So, essentially, I have two models, Ticket
class Ticket < ActiveRecord::Base
belongs_to :event
end
And Event:
class Event < ActiveRecord::Base
belongs_to :club
has_many :tickets
accepts_nested_attributes_for :tickets
end
They are associated with each other, and I have done the necessary migrations.
In the events/show view, it shows the event and then at the end I have a link to create a ticket, with this event's name passed as an id:
<%= link_to 'Add tickets', new_ticket_path(:id => @event.name) %>
This renders properly in the new ticket page, I have tested it in the new ticket view with <%= params[:id] %>
and it comes up correctly.
The tickets_controller's create
method is as follows:
def create
@ticket = Ticket.new(ticket_params)
@ticket.event_id = params[:id]
...
end
But when testing back in the events/show view
<% @tickets = Ticket.all %>
<% @tickets.each do |ticket| %>
<p><%= ticket.event_id %>--</p>
<% end %>
All of the event_id's come up empty.
Any suggestions?