Guest User

Untitled

a guest
May 25th, 2018
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. ## edit.html.erb
  2. <%=error_messages_for :user %>
  3. <% form_for @user do |f| %>
  4. <p><label for="user_login">Login</label><br />
  5. <%=f.text_field :login %></p>
  6. <p><label for="user_email">Email</label><br />
  7. <%=f.text_field :email %></p>
  8. <p><label for="user_password">Password</label><br />
  9. <%= f.password_field :password %></p>
  10. <p><label for="user_password_confirmation">Confirm Password</label><br/>
  11. <%=f.password_field :password_confirmation %></p>
  12. <% if logged_in? && current_user.administrator? %>
  13. <p><label for="user_administrator">Administrator</label><br />
  14. <%= f.check_box :administrator %></p>
  15. <% end %>
  16. <p><%=submit_tag 'Update'%></p>
  17. <% end %>
  18.  
  19. ## users_controller.rb
  20. def update
  21. @user = User.find(params[:id])
  22.  
  23. respond_to do |format|
  24. @user.attributes =params[:user]
  25. @user.administrator = params[:user][:administrator]
  26. if @user.save
  27. flash[:notice] = 'User was successfully updated.'
  28. format.html { redirect_to( :controller => "admin", :action => "menu") }
  29. format.xml { head :ok }
  30. else
  31. format.html {render :action => "edit" }
  32. format.xml { render :xml => @user.errors, :status => :unprocessable_entity }
  33. end
  34. end
  35. end
Add Comment
Please, Sign In to add comment