Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2016
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.73 KB | None | 0 0
  1. edit_user_registration GET /users/edit(.:format) devise/registrations#edit
  2.  
  3. devise_for :users
  4.  
  5. resources :users do
  6. collection do
  7. patch 'update_account'
  8. end
  9. end
  10.  
  11. root 'static_pages#home'
  12.  
  13. get '/users/:id', :to => 'users#show'
  14. get '/users/:id/edit', :to => 'users#edit'
  15.  
  16. get '/help', to: 'static_pages#help'
  17. get '/about', to: 'static_pages#about'
  18.  
  19. Prefix Verb URI Pattern Controller#Action
  20. new_user_session GET /users/sign_in(.:format) devise/sessions#new
  21. user_session POST /users/sign_in(.:format) devise/sessions#create
  22. destroy_user_session DELETE /users/sign_out(.:format) devise/sessions#destroy
  23. user_password POST /users/password(.:format) devise/passwords#create
  24. new_user_password GET /users/password/new(.:format) devise/passwords#new
  25. edit_user_password GET /users/password/edit(.:format) devise/passwords#edit
  26. PATCH /users/password(.:format) devise/passwords#update
  27. PUT /users/password(.:format) devise/passwords#update
  28. cancel_user_registration GET /users/cancel(.:format) devise/registrations#cancel
  29. user_registration POST /users(.:format) devise/registrations#create
  30. new_user_registration GET /users/sign_up(.:format) devise/registrations#new
  31. edit_user_registration GET /users/edit(.:format) devise/registrations#edit
  32. PATCH /users(.:format) devise/registrations#update
  33. PUT /users(.:format) devise/registrations#update
  34. DELETE /users(.:format) devise/registrations#destroy
  35. update_account_users PATCH /users/update_account(.:format) users#update_account
  36. users GET /users(.:format) users#index
  37. POST /users(.:format) users#create
  38. new_user GET /users/new(.:format) users#new
  39. edit_user GET /users/:id/edit(.:format) users#edit
  40. user GET /users/:id(.:format) users#show
  41. PATCH /users/:id(.:format) users#update
  42. PUT /users/:id(.:format) users#update
  43. DELETE /users/:id(.:format) users#destroy
  44. root GET / static_pages#home
  45. GET /users/:id(.:format) users#show
  46. GET /users/:id/edit(.:format) users#edit
  47. help GET /help(.:format) static_pages#help
  48. about GET /about(.:format) static_pages#about
  49.  
  50. <% if user_signed_in? %>
  51. <div class="dropdown"">
  52. <li class="dropdown-toggle" id="dropdownMenu1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
  53. <%= current_user.email %>
  54. <span class="caret"></span>
  55. </li>
  56. <ul class="dropdown-menu" aria-labelledby="dropdownMenu1">
  57. <li><%= link_to 'My Profile', what_path_goes_here? %></li>
  58. <li><%= link_to 'Account Settings', edit_user_registration_path %></li>
  59. <li><a href="#">Edit Profile</a></li>
  60. <li role="separator" class="divider"></li>
  61. <li><%= link_to 'Log out', destroy_user_session_path, method: :delete %></li>
  62. </ul>
  63. </div>
  64. <% elsif %>
  65. <li><%= link_to "Sign Up", new_user_registration_path %></li>
  66. <li><%= link_to "Sign In", new_user_session_path %></li>
  67. <% end %>
  68.  
  69. class UsersController < ApplicationController
  70. before_filter :authenticate_user!
  71.  
  72. def edit
  73. @user = current_user
  74. end
  75.  
  76. def update_account
  77. @user = User.find(current_user.id)
  78. if @user.update_with_password(user_params)
  79. # Sign in the user by passing validation in case their password changed
  80. sign_in @user, :bypass => true
  81. redirect_to root_path
  82. else
  83. render "edit"
  84. end
  85. end
  86.  
  87. private
  88.  
  89. def user_params
  90. params.require(:user).permit(:email, :password, :password_confirmation, :current_password)
  91. end
  92.  
  93. end
  94.  
  95. <% provide(:title, "Edit user") %>
  96.  
  97. <div class="container middle">
  98.  
  99. <!-- SideBar NEED TO REFACTOR TO A USER LAYOUT FILE -->
  100. <div class="sidebar col-md-3">
  101. </div>
  102.  
  103. <div class="main-content col-md-9">
  104.  
  105. <div class="main-breadcrumb">
  106. Some Content
  107. </div>
  108.  
  109. <div class="section_header">
  110. <h3>Edit Account</h3>
  111. </div>
  112.  
  113. <div class="row-fluid">
  114. <div class="col-md-6">
  115. <%= form_for(@user, :url => { :action => "update_account" } ) do |f| %>
  116.  
  117. <div class="field">
  118. <%= f.label :email %><br />
  119. <%= f.email_field :email, autofocus: true %>
  120. </div>
  121.  
  122. <div class="field">
  123. <%= f.label :password %> <i>(leave blank if you don't want to change it)</i><br />
  124. <%= f.password_field :password, autocomplete: "off" %>
  125. </div>
  126.  
  127. <div class="field">
  128. <%= f.label :password_confirmation %><br />
  129. <%= f.password_field :password_confirmation, autocomplete: "off" %>
  130. </div>
  131.  
  132. <div class="field">
  133. <%= f.label :current_password %> <i>(we need your current password to confirm your changes)</i><br />
  134. <%= f.password_field :current_password, autocomplete: "off" %>
  135. </div>
  136.  
  137. <div class="actions">
  138. <%= f.submit "Update" %>
  139. </div>
  140. <% end %>
  141.  
  142. <h3>Cancel my account</h3>
  143. # I removed the devise 'cancel account' functionality for now
  144.  
  145. <%= link_to "Back", :back %>
  146. </div>
  147. </div>
  148.  
  149. </div><!-- end main content section -->
  150.  
  151. </div><!-- end Container -->
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement