简体   繁体   English

Rails 3-表单提交问题

[英]Rails 3 - Form submission issues

I'm having trouble getting a for to submit from my show.html.erb page. 我在show.html.erb页面上无法提交要提交的文件。 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. 它是一个嵌套的表单,它从/ event / 1 / ticketbuilder / 1发送到同一页面,但是,当我提交表单时,Ig et会出现路由错误(没有路由匹配“ / event / 1 / ticketbuilder / 1”)尽管直接转到该网址就可以了。

#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. 似乎我可以使用“ 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"}

Any help or ideas would greatly appreciated 任何帮助或想法将不胜感激

Try event_ticketbuilder_index_path for the :url. 尝试使用event_ticketbuilder_index_path来获取:url。 You want the create action, which does not have an existing id yet. 您需要创建操作,该操作尚无现有ID。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM