一個唯一的ID,其值我有兩個車型優惠和餐館選擇會對模型
我想顯示每個餐廳的交易。我不希望他們鏈接在:restaurant_id
上,而是我希望他們鏈接在:restaurant_name
上。
我無法弄清楚的是如何在控制器
restaurant controller
def show
@restaurant = Restaurant.find(params[:id])
@deals = @restaurant.deals
end
show.html.erb
<% restaurant.deals.each do |deal| %>
<h2><center><%= deal.day %></center></h2>
<% end %>
任何想法上:restaurant_name
他們聯繫呢?
你的意思是這樣的嗎? http://stackoverflow.com/questions/17755815/ruby-on-rails-find-by-field-other-than-id – Matt 2014-09-05 20:31:58
@Matt,我認爲[that question](http://stackoverflow.com/問題/ 17755815/ruby-on-rails-find-by-field-other-than-id)是指'find',但是OP詢問'belongs_to' – 2014-09-05 20:38:41