ruby on rails - Custom POST routes for create action not fired up -


# explaining context

puts "i learning rails, building simple forum application." puts "i pretty satisfied got far routes... " puts "...still figuring them out." puts "been 2 days trying sorts of things." puts "this now, , not working expected." puts "any help/pointers appreciated! :)" 

# problem

puts "i want forum's create path '/helpcenter' , not '/helpcenter/cat'." puts "when access form create new forum , hit submit, " puts "the form post '/helpcenter' correctly (firebuged)" puts "but index, not create!" puts "i put debugger in create action not being called." 

# config/routes.rb

scope "/helpcenter"   resources :cat, :controller => "forums", :as => :forums     resources :topics , :controller => "forum_topics", :as => :topics     resources :posts, :controller => "forum_posts", :as => :posts   end end  match "/helpcenter" => "forums#index", :as => :forums match "/helpcenter" => "forums#create", :via => :post, :as => :create_forum 

i hope problem in way created route. tried many different things.

# _form.html.erb

<%= form_for(@forum) |f| %> .... <% end %> 

i using standard form_for helper.

# rake routes forums

$ controller=forums rake routes delete_forum    /helpcenter/cat/:id/delete(.:format) forums#delete       forums    /helpcenter/cat(.:format)            forums#index              post   /helpcenter/cat(.:format)            forums#create    new_forum    /helpcenter/cat/new(.:format)        forums#new   edit_forum    /helpcenter/cat/:id/edit(.:format)   forums#edit        forum    /helpcenter/cat/:id(.:format)        forums#show              put    /helpcenter/cat/:id(.:format)        forums#update              delete /helpcenter/cat/:id(.:format)        forums#destroy       forums        /helpcenter(.:format)                forums#index create_forum post   /helpcenter(.:format)                forums#create 

we see route post /helpcenter binded create action of forums controller.

# logs

started post "/helpcenter" 127.0.0.1 @ 2012-07-02 12:25:00 -0400 processing forumscontroller#index html   parameters: {"utf8"=>"✓", "authenticity_token"=>"d5ivkch234234=", "forum"=>{"name"=>"", "description"=>""}, "commit"=>"save changes"} 

the logs shows doing post on /helpcenter fires index action instead of create action!

# doing wrong?

puts "thanks!" 

i think request matches first forums route since didn't specify http method. should work:

match "/helpcenter" => "forums#index", :via => :get, :as => :forums match "/helpcenter" => "forums#create", :via => :post, :as => :create_forum 

or shorthand version:

get "/helpcenter" => "forums#index", :as => :forums post "/helpcenter" => "forums#create", :as => :create_forum 

Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c# - Copy ObservableCollection to another ObservableCollection -

All overlapping substrings matching a java regex -