I'm building an application in which i need to add rows to tables from multiple other models.
This is what i have so far (sorry for the sloppy code, first project with ruby/rails). I do realize that I am still missing some key elements to the code for this to function properly, I would just like to make sure I am going about this the right way first. I will also be moving the form to a partial once i get everything working correctly.
# app/views/ticketbuilder/show.html.erb
<ul>
<% @event.sections.each do |s| %>
<li><%= s.name %></li>
<ul>
<% s.locations.each do |l| %>
<li><%= l.name %></li>
<% end %>
</ul>
<% end %>
<li>
<%= form_for([:event, :ticketbuilder], :url => event_ticketbuilder_url) do |s| %>
<%= s.text_field(:section) %> <%= submit_tag("Add Section") %>
<%= s.hidden_field(:event_id, @event.id) %>
<% end %>
</li>
</ul>
# routes.rb
resources :event do
resources :ticketbuilder
end
# ticketbuilder_controller.rb
class TicketbuilderController < ApplicationController
def show
@event = Event.find(params[:event_id])
end
def new
@section = Section.new
respond_to do |format|
format.html # new.html.erb
format.xml { render :xml => @event }
end
end
end
# error message
undefined method `model_name' for Symbol:Class
The problem I am having is sending the form to the ticketbuilder controller. What I'm trying to accomplish is to have a list of seating sections with child elements for locations. I would like to be able to add new sections and locations directly on the list page.
Any suggestions would be greatly appreciated.