Hi,
I am quite new to Rails3, I basically created a subscribers
scaffolding, I only want my app to respond to new
and create
actions.
So in config/routes.rb
I defined:
resources :subscribers, :only => [:new, :create]
Which works this way
GET /subscribers => subscribers#new POST /subscribers => subscribers#create
Now I want my app to exhibit the subscribers resources at /
(root) instead of /subscribers
, so here is what I did:
match '/' => "subscribers#new" match '/' => "subscribers#create" match '/' => "subscribers#thankyou" resources :subscribers, :only => [:new, :create]
Which somehow works, but is probably not the DRYest thing: here are the issues I have:
- When going back to the form after an issue on a create the browser displays the
/subscribers
URL instead of just/
, the form is created using theform_for(@subscriber)
helper method, so thepath
helper must be somehow unaffected by the route - Ideally I don't even want the app to respond to a request on
/subscribers
- I noticed a weird bug, when posting the form while disconnected (from
/
, and then doing a refresh when the connection comes back (browser ask for resubmitting => OK), the Rails app crashes (I don't have the error stack though as this was on production), why is that?
Also, I tried setting up the route this way:
resources :subscribers, :only => [:new, :create] do collection do post '/' => :create get '/' => :new end end
Which is probably DRYer, but it doesn't fix any of these issues.
I am sure this is something quite simple, please help!