我试着让这个有条件:
<% 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 %>但是boutique_kind(3)展示了所有的精品店!我是如何得到精品店的boutiques_kind id 3的方法!
boutiqueKind控制器
def show
@boutique_kind = BoutiqueKind.find(params[:id])
endboutiqueKind模型
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精品控制器
class Boutique < ActiveRecord::Base
belongs_to :user
belongs_to :boutique_kind
end发布于 2014-05-29 20:40:50
您应该可以通过ID找到专卖店:
BoutiqueKind.find(3)如果我误解了,并且id不是唯一的id (在这种情况下,我建议您将该列重命名为id以外的东西),那么您可以获得所有记录,其中某个字段的==是一个特定的值:
BoutiqueKind.where(id: 3)https://stackoverflow.com/questions/23941376
复制相似问题