ruby on rails - Customising Devise registration edit/update routes and views -
i've started using devise , i've made customisations:
- i've generated views , customised views (signup form etc)
- i've generated controllers can make changes there
- i've customised routes, per post: http://iampedantic.com/post/41170460234/fully-customizing-devise-routes
everything works great except edit_user_registration stuff (the view users can change email , password or delete account).
this have registrations in config/routes.rb
(parts not related registrations controller omitted):
devise_for :users, skip: [:registrations] :user # joining '/register' => 'users/registrations#new', as: 'new_user_registration' post '/register' => 'users/registrations#create', as: 'user_registration' scope '/user' # settings & cancellation '/cancel' => 'users/registrations#cancel', as: 'cancel_user_registration' '/settings' => 'users/registrations#edit', as: 'edit_user_registration' patch '/settings' => 'users/registrations#update' # account deletion delete '' => 'users/registrations#destroy' end
i changed put
patch
because i'm using rails 4 (is correct?).
this form_for tag in views/users/registrations/edit.html.erb
:
<%= form_for(resource, as: resource_name, url: registration_path(resource_name), html: { method: :patch }) |f| %>
when try update settings user above code, 500 internal server error. submitting form attempts load /register
(my signup page), surely not right. (i think heart of problem don't understand how fix i'm quite beginner.)
when try update settings user original put
method (instead of patch
), same problem.
my development web server says:
actioncontroller::routingerror (no route matches [put] "/register"):
thanks in advance.
edit: added rake routes
output below.
prefix verb uri pattern controller#action new_user_registration /register(.:format) users/registrations#new user_registration post /register(.:format) users/registrations#create cancel_user_registration /user/cancel(.:format) users/registrations#cancel edit_user_registration /user/settings(.:format) users/registrations#edit settings put /user/settings(.:format) users/registrations#update delete /user(.:format) users/registrations#destroy
edit 2: rakes routes
looks when remove custom routes , let devise handle registrations views etc.:
prefix verb uri pattern controller#action new_user_registration /users/sign_up(.:format) devise/registrations#new user_registration post /users(.:format) devise/registrations#create cancel_user_registration /users/cancel(.:format) devise/registrations#cancel edit_user_registration /users/edit(.:format) devise/registrations#edit patch /users(.:format) devise/registrations#update put /users(.:format) devise/registrations#update delete /users(.:format) devise/registrations#destroy
working:
routes.rb:
get 'settings' => 'users/registrations#edit', as: 'edit_user_registration' put 'settings/:id' => 'users/registrations#update', as: 'update_user_registration'
edit.html.erb:
<%= form_for(resource, as: resource_name, url: update_user_registration_path(resource_name), html: { method: :put }) |f| %>
the problem registration_path
submitting form /register
, new users, you're trying edit existing user
object, need submit correct update path. default, that's put /users/:id
see when remove configurations.
it looks customizations have set user
update path put /user/settings
, try url: settings_path
. you're aiming users/registrations#update
action seen in row:
prefix verb uri pattern controller#action settings put /user/settings(.:format) users/registrations#update
Comments
Post a Comment