Commit fd6e72ea
Changed files (4)
app
controllers
admin
views
admin
config
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
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>
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>
+
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]