ruby on rails - No route matches {:action=>"change_name", :controller=>"users", :id=>nil} missing required keys: [:id] -
i've added gem "devise" , got error. can't understand what's wrong code. in advance!
error:
def user_form common_options = { validate: true, html: { class: 'user-form' } } form_options = current_user ? [ current_user, { url: change_user_name_path(current_user.id), method: :post, validate: true }.merge(common_options) ] : [ user.new, { validate: true }.merge(common_options) ] form_for *form_options |f| yield f end end
routes
rails.application.routes.draw devise_for :users devise_for :usernames root 'surveys#index' resources 'surveys' resources 'attempts' resources 'users', only: [:create] delete 'attempts/:survey_id/:user_id' => 'attempts#delete_user_attempts', as: :delete_user_attempts post 'user/:id/change_name' => 'users#change_name', as: :change_user_name
controller:
class userscontroller < applicationcontroller def create session[:user_id] = user.create(user_params).id redirect_to :back end def change_name @user = user.find(params[:id]) @user.update(user_params) redirect_to :back end def user_params params.require(:user).permit(:name) end end
can problem?
try remove method current_user
model. because current_user
default method of devise return current logged in user. overriding method of devise. that's why getting error of nil id
because current_user don't has value.
it solve problem .
Comments
Post a Comment