Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 如何仅显示用户名为“的内容?”;abc";?_Ruby On Rails_Ruby_Authentication_Devise - Fatal编程技术网

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魔术