Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## users_controller.rb
- def edit
- @roles = Role.find(:all)
- @user = User.find(params[:id])
- end
- def update
- @user = User.find(params[:id])
- respond_to do |format|
- if @user.update_attributes(params[:user])
- flash[:notice] = "User '#{@user.name}' was successfully updated."
- format.html { redirect_to(@user) }
- format.xml { head :ok }
- else
- flash[:error] = "There was a problem updating the user. No users were updated."
- render :action => 'edit'
- end
- end
- end
- ## error (after submitting with bad password confirmation)
- Showing users/edit.html.erb where line #25 raised:
- You have a nil object when you didn't expect it!
- You might have expected an instance of Array.
- The error occurred while evaluating nil.map
- Extracted source (around line #25):
- 22: <%= f.password_field :password_confirmation %></p>
- 23:
- 24: <p><%= label_tag 'role' %><br/>
- 25: <%= collection_select(:user, :role_id, @roles, :id, :name) %></p>
- 26:
- 27:
- 28: <p style="margin-top: 20px"><%= f.submit 'Update' %></p>
- ## edit.html.erb
- <div class="form">
- <h1>Edit user</h1>
- <% @user.password = @user.password_confirmation = nil %>
- <%= error_messages_for :user %>
- <% form_for(@user) do |f| %>
- <p><%= f.label 'login' %><br/>
- <%= f.text_field :login %></p>
- <p><%= label_tag 'name' %><br/>
- <%= f.text_field :name %></p>
- <p><%= label_tag 'email' %><br/>
- <%= f.text_field :email %></p>
- <p><%= label_tag 'password' %><br/>
- <%= f.password_field :password %></p>
- <p><%= label_tag 'password_confirmation', 'Confirm Password' %><br/>
- <%= f.password_field :password_confirmation %></p>
- <p><%= label_tag 'role' %><br/>
- <%= collection_select(:user, :role_id, @roles, :id, :name) %></p>
- <p style="margin-top: 20px"><%= f.submit 'Update' %></p>
- <% end -%>
- </div>
Add Comment
Please, Sign In to add comment