2011-03-27 70 views
0

我无法从show.html.erb页面提交申请。它是从/ event/1/ticketbuilder/1发送到同一页面的嵌套表单,但是,当我提交表单时,Ig等于路由错误(无路由匹配“/ event/1/ticketbuilder/1”),甚至尽管去那个网址直接工作就好了。Rails 3 - 表单提交问题

#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 

当直接链接到页面,它成功,我也得到

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) 

当提交页面上的形式,我得到

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) 

它好像我可以访问使用“GET”方法但不使用“POST”的页面我假设这与通过URL发送的变量有关,但目前我还没有足够的有关rails的知识来解决此问题。

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"} 

任何帮助或想法,将不胜感激

+1

运行'rake routes'来查看哪些路由可用,以及它们响应哪个HTTP方法。这应该会让您更深入地了解问题。 – 2011-03-27 19:17:46

+0

发布您的routes.rb – Shiv 2011-03-27 19:18:27

+0

为控制器添加了“rake routes”输出。我看到的一个问题是,“/ event/1/ticketbuilder/1”末尾的“/ 1”可能导致问题。感谢您的意见 – 2011-03-27 19:25:23

回答

1

尝试event_ticketbuilder_index_path为:URL。您需要创建操作,该操作尚未具有现有标识。