0

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?

0

1 Answer 1

1

undefined local variable or method `table_id' for Ticket......

That means, while table_id is passed with pathnew_from_table_path(:table_id => table.id) at controller#action this parameter table_id will be taken dynamically as params[:table_id]

  def new_from_table
    @ticket = Ticket.new(table_id: params[:table_id])
  end
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.