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"}
任何幫助或想法,將不勝感激
運行'rake routes'來查看哪些路由可用,以及它們響應哪個HTTP方法。這應該會讓您更深入地瞭解問題。 – 2011-03-27 19:17:46
發佈您的routes.rb – Shiv 2011-03-27 19:18:27
爲控制器添加了「rake routes」輸出。我看到的一個問題是,「/ event/1/ticketbuilder/1」末尾的「/ 1」可能導致問題。感謝您的意見 – 2011-03-27 19:25:23