Ruby on rails 如何仅显示用户名为“的内容?”;abc";?
我有一个东西模型:Ruby on rails 如何仅显示用户名为“的内容?”;abc";?,ruby-on-rails,ruby,authentication,devise,Ruby On Rails,Ruby,Authentication,Devise,我有一个东西模型: class Thing < ActiveRecord::Base belongs_to :user has_attached_file :image, :styles => { :medium => '300x300>', :thumb => '100x100>' } validates :image, presence: true validates :description, presence: true end
class Thing < ActiveRecord::Base
belongs_to :user
has_attached_file :image, :styles => { :medium => '300x300>', :thumb => '100x100>' }
validates :image, presence: true
validates :description, presence: true
end
class Thing{:medium=>'300x300>,:thumb=>'100x100>'
验证:映像,状态:true
验证:描述,状态:true
结束
我还有一个用户模型:
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
has_many :things
validates :name, presence: true
validates :username, presence: true
validates :email, presence: true
end
class用户
我的UsersController如下所示:
class UsersController < ApplicationController
def show
@user = User.find_by_username(params[:username])
end
end
class UsersController
当我导航到localhost:3000/users/Delacram(其中Delacram是用户名)时,如何仅显示用户名为Delacram的内容?如果您有
@user
,其中包含许多内容
:
@user.things
您可以在其上循环:
@user.things.each do |thing|
= thing.description
...
假设您有一个
@user
,它有许多东西
:
@user.things
您可以在其上循环:
@user.things.each do |thing|
= thing.description
...
假设您有一个
@user
,它有许多东西
:
@user.things
您可以在其上循环:
@user.things.each do |thing|
= thing.description
...
假设您有一个
@user
,它有许多东西
:
@user.things
您可以在其上循环:
@user.things.each do |thing|
= thing.description
...
还有。。。在控制器中,您可以调用
@things=@user.things
的实例。然后在视图中,可以调用=render@things
。这将查看视图/things/_thing.html.haml
,并为@thing的每个实例将该文件中的任何内容放到页面上
Rails magic…还有。。。在控制器中,您可以调用
@things=@user.things
的实例。然后在视图中,可以调用=render@things
。这将查看视图/things/_thing.html.haml
,并为@thing的每个实例将该文件中的任何内容放到页面上
Rails magic…还有。。。在控制器中,您可以调用
@things=@user.things
的实例。然后在视图中,可以调用=render@things
。这将查看视图/things/_thing.html.haml
,并为@thing的每个实例将该文件中的任何内容放到页面上
Rails magic…还有。。。在控制器中,您可以调用
@things=@user.things
的实例。然后在视图中,可以调用=render@things
。这将查看视图/things/_thing.html.haml
,并为@thing的每个实例将该文件中的任何内容放到页面上
Rails魔术