问题
I have a Query resource that I want to route to the root of my domain. (So posting to "/" goes to the queries#create
action, etc...).
My routes.rb:
root :to => "home#index"
resources :queries, :path => ''
rake routes:
root / home#index
queries GET / queries#index
POST / queries#create
All seems fine, but when I try to post to "/", it is somehow getting routed to the 'root_path', even though I'm submitting it via POST
. So instead of creating a new Query item, it just reloads the home page. I get this in the log:
Started POST "/" for 127.0.0.1 at 2012-04-16 20:34:58 -0400
Processing by HomeController#index as HTML
Any idea what I'm doing wrong?
Edit
When I move :root =>
to the very bottom of the controller, I get a redirect loop when I GET "/"
, which is why my ':root' definition isn't at the bottom.
Edit
It works when I replace the :root definition with get "/" => "home#index", :as => "root"
, but that feels too hackish to me. How do I specify what HTTP verbs to use on the root
definition?
回答1:
This works:
get "/" => "home#index", :as => "root"
回答2:
Are you passing the :url => {:action = "create"} or the method in your form_for?
来源:https://stackoverflow.com/questions/10183585/rails-routes-resourcing-from-the-root-path