I have models Ticket and Table. Ticket belongs to Table.
I want to show an index of tables, each one should have a button to a new ticket with corresponding table assigned.
tickets controller:
def new_from_table
@ticket = Ticket.new(table_id: table_id)
end
and in my view:
<% @tables.each do |table| %>
<tr>
<td><%= table.name %></td>
<td><%= link_to 'Add', new_from_table_path(:table_id => table.id), class: "btn btn-sm btn-success" %></td>
</td>
</tr>
and routes:
get 'new_from_table', to: 'tickets#new_from_table', as: :new_from_table
But I can't figure out how to pass table.id on loop to ticket.table_id.
Solution above returns:
undefined local variable or method `table_id' for Ticket......
Any suggestion?