access params hash in controller
I have a link
<%= link_to 'Add link', new_link_path(:link => {:item1_id => @i开发者_StackOverflow中文版tem.id}) %>
passing to
def new
@link = Link.new(params[:link])
@items = Item.all
form is
<%= form_for(@link) do |f| %>
<%= f.hidden_field :item1_id %>
<%= f.collection_select :item2_id , Item.all , :id , :name %>
So I want to access like the image linked to the item1_id item. How do I access it? i tried
@item1 = Item.find_by_id(params[:link])
and
@item1 = Item.find_by_id(params[:item_id])
but I don't know what is right.
try:
@item1 = Item.find(params[:link][:item1_id])
looks like you need:
@item1 = Item.find_by_id(params[:link][:item1_id])
精彩评论