How to remove ControllerName from a Rails Resource? -
i wish map new_user path of user resource 'root_domain/new' url. routes.rb looks this:
#new_user /users/new(.:format) users#new # user resource match 'new', :to => 'users#new', via: [:get, :post] resources :users collection match 'new', :to => 'users#new', via: [:get, :post] end end so while i'm able hit /new url desired action with
match 'new', :to => 'users#new', via: [:get, :post] but new_user path still leads '/users/new'. how remove controller_name new_user method?
your new_user_path takes user#new because that's how rails build resourceful routes. have @ rails guides learn more. need pass as: option routes in order give them proper helper methods like:
post '/home' => "home#index", as: :home this give 2 helpers home_path , home_url
now have
resources :users collection match 'new', :to => 'users#new', via: [:get, :post] end end if rake routes in terminal you'll see new_user helpers assigned user#new. you need give different path helper , assign new_user helpers custom route
resources :users collection match 'new', :to => 'users#new', via: [:get, :post], as: :old_new_user end end and can use new_user helper custom route
match 'new', :to => 'users#new', via: [:get, :post], as: :new_user you can check path helper doing rake routes in terminal
Comments
Post a Comment