Reputation: 73
I'm having trouble getting a for to submit from my show.html.erb page. It is a nested form that sends from /event/1/ticketbuilder/1 to the same page, However, when i submit the form, Ig et a Routing Error (No route matches "/event/1/ticketbuilder/1") even though going to that url directly works just fine.
#show.html.erb
<%= form_for @section, :url => event_ticketbuilder_path(@event) do |s| %>
<%= s.text_field(:name) %> <%= submit_tag("Add Section") %>
<% end %>
#ticketbuilder_controller.rb
class TicketbuilderController < ApplicationController
def show
@event = Event.find(params[:event_id])
@section = Section.new
end
def create
@event = Event.new(params[:event_id])
@section = @event.sections.build(params[:name])
if @section.save
@section = Section.new
end
render :action => :show
end
end
When linking directly to the page, it succeeds and i get
Started GET "/event/1/ticketbuilder/1" for 206.248.211.83 at Sun Mar 27 15:02:24 -0400 2011
Processing by TicketbuilderController#show as HTML
Parameters: {"event_id"=>"1", "id"=>"1"}
Event Load (0.3ms) SELECT "events".* FROM "events" WHERE "events"."id" = 1 LIMIT 1
Section Load (0.3ms) SELECT "sections".* FROM "sections" WHERE ("sections".event_id = 1)
Location Load (0.3ms) SELECT "locations".* FROM "locations" WHERE ("locations".section_id = 1)
User Load (0.4ms) SELECT "users".* FROM "users" WHERE "users"."id" = 1 LIMIT 1
Rendered ticketbuilder/show.html.erb within layouts/application (52.2ms)
Completed 200 OK in 85ms (Views: 56.8ms | ActiveRecord: 1.4ms)
When submitting the form on that page i get
Started POST "/event/1/ticketbuilder/1" for 206.248.211.83 at Sun Mar 27 15:02:26 -0400 2011
ActionController::RoutingError (No route matches "/event/1/ticketbuilder/1"):
Rendered /usr/lib/ruby/gems/1.8/gems/actionpack-3.0.5/lib/action_dispatch/middleware/templates/rescues/routing_error.erb within rescues/layout (1.0ms)
It seems as though I can access the page with the "GET" method but not "POST" I assume this has something to do with the variables being sent through the URL, but I don't have enough knowledge of rails currently to solve this.
event_ticketbuilder_index GET /event/:event_id/ticketbuilder(.:format) {:controller=>"ticketbuilder", :action=>"index"}
POST /event/:event_id/ticketbuilder(.:format) {:controller=>"ticketbuilder", :action=>"create"}
new_event_ticketbuilder GET /event/:event_id/ticketbuilder/new(.:format) {:controller=>"ticketbuilder", :action=>"new"}
edit_event_ticketbuilder GET /event/:event_id/ticketbuilder/:id/edit(.:format) {:controller=>"ticketbuilder", :action=>"edit"}
event_ticketbuilder GET /event/:event_id/ticketbuilder/:id(.:format) {:controller=>"ticketbuilder", :action=>"show"}
PUT /event/:event_id/ticketbuilder/:id(.:format) {:controller=>"ticketbuilder", :action=>"update"}
DELETE /event/:event_id/ticketbuilder/:id(.:format) {:controller=>"ticketbuilder", :action=>"destroy"}
event_index GET /event(.:format) {:controller=>"event", :action=>"index"}
POST /event(.:format) {:controller=>"event", :action=>"create"}
GET /event/new(.:format) {:controller=>"event", :action=>"new"}
GET /event/:id/edit(.:format) {:controller=>"event", :action=>"edit"}
GET /event/:id(.:format) {:controller=>"event", :action=>"show"}
PUT /event/:id(.:format) {:controller=>"event", :action=>"update"}
DELETE /event/:id(.:format) {:controller=>"event", :action=>"destroy"}
Any help or ideas would greatly appreciated
Upvotes: 0
Views: 396
Reputation: 26979
Try event_ticketbuilder_index_path for the :url. You want the create action, which does not have an existing id yet.
Upvotes: 1