Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/62.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 rails如何在查看页面上获取相关id_Ruby On Rails_Ruby_Ruby On Rails 3_Ruby On Rails 4 - Fatal编程技术网

Ruby on rails rails如何在查看页面上获取相关id

Ruby on rails rails如何在查看页面上获取相关id,ruby-on-rails,ruby,ruby-on-rails-3,ruby-on-rails-4,Ruby On Rails,Ruby,Ruby On Rails 3,Ruby On Rails 4,我正试图将此条件化: <% if current_boutique.boutique_kind(3) %> Brand: <span><%= current_boutique.name %></span> <% else %> <%= p.input :brand_id, :as => :select, :collection=> Brand.find(:all, :order=>:name).coll

我正试图将此条件化:

<% if current_boutique.boutique_kind(3) %>
  Brand: <span><%= current_boutique.name %></span>

  <% else %>
<%= p.input :brand_id, :as => :select, :collection=> Brand.find(:all, :order=>:name).collect{ |b| [b.name,b.id,  b.name]},
  :label => "Marca", :prompt => 'Select Brand', :required => true  %>

<% end %>
精品模型

 attr_accessible :kind, :slug

  has_many                      :boutiques
  has_many                      :products, :through => :boutiques
  #belongs_to                    :gender
  accepts_nested_attributes_for :boutiques
  attr_accessible               :boutiques, :boutiques_attributes, :kind
精品店总监

def show 
  @boutique_kind = BoutiqueKind.find(params[:id])
end
class Boutique < ActiveRecord::Base
  belongs_to :user
  belongs_to :boutique_kind
end
class精品
您应该可以通过以下ID找到精品店:

BoutiqueKind.find(3)
如果我误解了,并且id不是唯一的id(在这种情况下,我建议您将列重命名为id以外的其他名称),那么您可以获得所有记录,其中某个字段==一个特定值,具有:

BoutiqueKind.where(id: 3)

你能展示一下这个方法的主体吗?好的,控制器上的方法还是模型上的方法?你为什么问我?这是你的密码。。Lollz:)不确定你上次对问题的编辑是否包括了
精品类
方法(因为它是在你上次评论之后)。不管怎样,您正在调用当前精品店上的方法,我想这是一种返回模型的方法……嗯。。。不,那不是那种“精品”的方法。至于模型,我们也需要类声明。
kind.where(id:3)。首先
但是我可以在查看页面上添加此方法吗?可以,但是它违反了MVC规则。最好将它放在控制器中,并为其指定一个变量名,然后在视图中引用该变量。如果它起作用,您介意单击我答案上的复选标记吗?这是我们老鼠吃的奶酪。