diff options
| author | mo khan <mo@mokhan.ca> | 2014-10-19 19:20:46 -0600 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2014-10-19 19:20:46 -0600 |
| commit | fd6e72ea6fb5caeadb09a48642cda1f1b36cb645 (patch) | |
| tree | 3e68ffe8d414ee3bb6020c5649e2348d10d1ef26 | |
| parent | d8e204f69c8317f04dcfc5f43c6f992d4fbfa9a3 (diff) | |
add way to update info on a user.
| -rw-r--r-- | app/controllers/admin/users_controller.rb | 10 | ||||
| -rw-r--r-- | app/views/admin/users/_edit_modal.html.erb | 56 | ||||
| -rw-r--r-- | app/views/admin/users/_index.html.erb | 38 | ||||
| -rw-r--r-- | config/routes.rb | 16 |
4 files changed, 95 insertions, 25 deletions
diff --git a/app/controllers/admin/users_controller.rb b/app/controllers/admin/users_controller.rb index 67dbb95d..11443d5b 100644 --- a/app/controllers/admin/users_controller.rb +++ b/app/controllers/admin/users_controller.rb @@ -13,8 +13,18 @@ module Admin @user = repository.includes(creations: :photos).find(params[:id]) end + def update + @user = User.find(params[:id]) + @user.update(secure_params) + redirect_to :back + end + private + def secure_params + params.require(:user).permit(:name, :email, :city, :website, :twitter, :facebook) + end + attr_reader :repository end end diff --git a/app/views/admin/users/_edit_modal.html.erb b/app/views/admin/users/_edit_modal.html.erb new file mode 100644 index 00000000..07452d5e --- /dev/null +++ b/app/views/admin/users/_edit_modal.html.erb @@ -0,0 +1,56 @@ +<div id="edit-user-modal-<%= user.id %>" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"> + <div class="modal-header"> + <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> + <h3 id="myModalLabel">Edit <%= user.name %></h3> + </div> + <%= form_for user, url: admin_user_path(user), method: :put, html: { class: 'form-horizontal' } do |f| %> + <div class="modal-body"> + <div class="control-group"> + <%= f.label :name, class: 'control-label' %> + <div class="controls"> + <%= f.text_field :name %> + <span class="help-inline"></span> + </div> + </div> + <div class="control-group"> + <%= f.label :email, class: 'control-label' %> + <div class="controls"> + <%= f.text_field :email %> + <span class="help-inline"></span> + </div> + </div> + <div class="control-group"> + <%= f.label :city, class: 'control-label' %> + <div class="controls"> + <%= f.text_field :city %> + <span class="help-inline"></span> + </div> + </div> + <div class="control-group"> + <%= f.label :website, class: 'control-label' %> + <div class="controls"> + <%= f.url_field :website %> + <span class="help-inline"></span> + </div> + </div> + <div class="control-group"> + <%= f.label :twitter, class: 'control-label' %> + <div class="controls"> + <%= f.text_field :twitter %> + <span class="help-inline"></span> + </div> + </div> + <div class="control-group"> + <%= f.label :facebook, class: 'control-label' %> + <div class="controls"> + <%= f.url_field :facebook %> + <span class="help-inline"></span> + </div> + </div> + </div> + <div class="modal-footer"> + <button class="btn" data-dismiss="modal" aria-hidden="true">Close</button> + <%= f.submit "Save Changes", class: 'btn btn-primary', disable_with: "Saving..." %> + </div> + <% end %> +</div> diff --git a/app/views/admin/users/_index.html.erb b/app/views/admin/users/_index.html.erb index 3f9539f9..5825cc60 100644 --- a/app/views/admin/users/_index.html.erb +++ b/app/views/admin/users/_index.html.erb @@ -9,28 +9,32 @@ created at <%= link_to url_for(params.merge(sort: "newest")), remote: true do %> <i class="fa fa-sort-up"></i> - <% end %> + <% end %> <%= link_to url_for(params.merge(sort: "oldest")), remote: true do %> <i class="fa fa-sort-down"></i> - <% end %> + <% end %> </td> </tr> </thead> <tbody> - <%- @users.each do |user| %> - <tr> - <td>edit</td> - <td><%= link_to "#{user.name} (#{user.creations_count})", admin_user_path(user) %></td> - <td><%= mail_to user.email %></td> - <td> - <ul> - <%= "<li>#{user.website}</li>".html_safe unless user.website.blank? %> - <%= "<li>#{user.twitter}</li>".html_safe unless user.twitter.blank? %> - <%= "<li>#{user.facebook}</li>".html_safe unless user.facebook.blank? %> - </ul> - </td> - <td><%= user.created_at.strftime("%Y-%m-%d") %></td> - </tr> - <% end %> + <%- @users.each do |user| %> + <tr> + <td> + <a href="#edit-user-modal-<%= user.id %>" role="button" data-toggle="modal">edit</a> + <%= render partial: 'edit_modal', locals: { user: user } %> + </td> + <td><%= link_to "#{user.name} (#{user.creations_count})", admin_user_path(user) %></td> + <td><%= mail_to user.email %></td> + <td> + <ul> + <%= "<li>#{user.website}</li>".html_safe unless user.website.blank? %> + <%= "<li>#{user.twitter}</li>".html_safe unless user.twitter.blank? %> + <%= "<li>#{user.facebook}</li>".html_safe unless user.facebook.blank? %> + </ul> + </td> + <td><%= user.created_at.strftime("%Y-%m-%d") %></td> + </tr> + <% end %> </tbody> </table> + diff --git a/config/routes.rb b/config/routes.rb index f0014843..632bbac7 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -7,9 +7,9 @@ Cake::Application.routes.draw do post 'comments', to: 'comments#create' resources :tutorials, only: [:index, :show] do - get 'page/:page', :action => :index, :on => :collection + get 'page/:page', action: :index, on: :collection end - resources :tutorial_tags, :only => [:index, :show], :path => :tt do + resources :tutorial_tags, only: [:index, :show], path: :tt do member do get 'page/:page', action: :show end @@ -17,7 +17,7 @@ Cake::Application.routes.draw do resources :cakes, only: [:index, :show], path: :cakes do resources :photos, only: [:index, :show] - resources :favorites, :only => [:index, :create] + resources :favorites, only: [:index, :create] get 'page/:page', action: :index, on: :collection, as: :paginate collection do get :newest, action: 'index', sort: 'newest' @@ -30,12 +30,12 @@ Cake::Application.routes.draw do get 'creations/:id', to: redirect('/cakes/%{id}') get 'creations/page/:page', to: redirect('/cakes/page/%{page}') - resources :profiles, :only => [:index, :show] do - get 'page/:page', :action => :index, :on => :collection, as: :paginate + resources :profiles, only: [:index, :show] do + get 'page/:page', action: :index, on: :collection, as: :paginate end # /tags - resources :creation_tags, :only => [:index, :show], :path => :t do + resources :creation_tags, only: [:index, :show], path: :t do member do get 'page/:page', action: :show end @@ -70,8 +70,8 @@ Cake::Application.routes.draw do end namespace :admin do - root :to => "users#index" - resources :users, only: [:index, :show] + root to: "users#index" + resources :users, only: [:index, :show, :update] resources :jobs, only: [:index, :show, :update, :destroy] resources :activities, only: [:index] resources :subscriptions, only: [:index] |
