Dodałem regułkę w routes.rb
[code=ruby] devise_for :users, :path_names => { :sign_up => “register”,
:sign_in => “login”, :sign_out => “logout” }
namespace :admin do
resources :users, :except => [:new, :create]
put “/users/:id”, :to => “users#update”, :as => :user_update
end[/code]
rake routes:
new_user_session GET /users/login(.:format) {:action=>"new", :controller=>"devise/sessions"}
user_session POST /users/login(.:format) {:action=>"create", :controller=>"devise/sessions"}
destroy_user_session GET /users/logout(.:format) {:action=>"destroy", :controller=>"devise/sessions"}
user_password POST /users/password(.:format) {:action=>"create", :controller=>"devise/passwords"}
new_user_password GET /users/password/new(.:format) {:action=>"new", :controller=>"devise/passwords"}
edit_user_password GET /users/password/edit(.:format) {:action=>"edit", :controller=>"devise/passwords"}
PUT /users/password(.:format) {:action=>"update", :controller=>"devise/passwords"}
user_registration POST /users(.:format) {:action=>"create", :controller=>"devise/registrations"}
new_user_registration GET /users/register(.:format) {:action=>"new", :controller=>"devise/registrations"}
edit_user_registration GET /users/edit(.:format) {:action=>"edit", :controller=>"devise/registrations"}
PUT /users(.:format) {:action=>"update", :controller=>"devise/registrations"}
DELETE /users(.:format) {:action=>"destroy", :controller=>"devise/registrations"}
admin_users GET /admin/users(.:format) {:action=>"index", :controller=>"admin/users"}
edit_admin_user GET /admin/users/:id/edit(.:format) {:action=>"edit", :controller=>"admin/users"}
admin_user GET /admin/users/:id(.:format) {:action=>"show", :controller=>"admin/users"}
PUT /admin/users/:id(.:format) {:action=>"update", :controller=>"admin/users"}
DELETE /admin/users/:id(.:format) {:action=>"destroy", :controller=>"admin/users"}
admin_user_update PUT /admin/users/:id(.:format) {:controller=>"admin/users", :action=>"update"}
_form.html.erb
[code=ruby]<%= form_for admin_user_update_path(@admin_user) do |f| %>
<% if @admin_user.errors.any? %>
<%= pluralize(@admin_user.errors.count, “error”) %> prohibited this admin_user from being saved:
<ul>
<% @admin_user.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<%= f.label :name %>
<%= f.text_field :name %>
<%= f.submit %>
<% end %>[/code]
Ale nadal błąd:
[code=ruby]Routing Error
No route matches “/admin/users/2/edit”[/code]
Edycja:
Tak z ciekawości badałem też inne CRUDy w moim projekcie i coś nie bangla destroy nigdzie.
Mogę wszędzie robić(poza admin/users) nowy rekord, wyświetlać go, modyfikować, natomiast destroy zawszę wywala ten sam błąd:
ActionController::InvalidAuthenticityToken