设计自定义路线

时间:2011-07-21 14:22:07

标签: ruby-on-rails devise

当用户进入

  

/帐户/编辑

点击提交按钮重定向到

  

/注册

路径?任何帮助将不胜感激。

路由

devise_for :users, :skip => [:registrations, :sessions] do
  get 'signup' => 'devise/registrations#new', :as => :new_user_registration
  post 'signup' => 'devise/registrations#create', :as => :user_registration
  get 'users/cancel' => 'devise/registrations#cancel', :as => :cancel_user_registration
  get 'account/edit' => 'devise/registrations#edit', :as => :edit_user_registration
  put 'account' => 'devise/registrations#update'
  delete 'users' => 'devise/registrations#destroy'

  get 'signin' => 'devise/sessions#new', :as => :new_user_session
  post 'signin' => 'devise/sessions#create', :as => :user_session
  get 'signout' => 'devise/sessions#destroy', :as => :destroy_user_session
end

注册/ edit.html.erb

<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name), :html => { :method => :put }) do |f| %>
<% if resource.errors.any? %>
    <div id="error_explanation">
      <ul>
      <% resource.errors.full_messages.each do |msg| %>
        <li><%= msg %></li>
      <% end %>
      </ul>
    </div>
<% end %>
<div class="field">
    <%= f.label :email %><br/>
  <%= f.email_field :email %>
</div>
<div class="field">
  <%= f.label :password %><br/>
  <%= f.password_field :password %>
</div>
<div class="field">
  <%= f.label :password_confirmation %><br/>
  <%= f.password_field :password_confirmation %>
</div>
<div class="field">
  <%= f.label :current_password %><br/>
  <%= f.password_field :current_password %>
</div>
<div class="actions">
  <%= f.submit %>
</div>
<% end %>

1 个答案:

答案 0 :(得分:1)

据我所知,有两种可能的解决方案。

解决方案#1:

更改此行:

post 'signup' => 'devise/registrations#create', :as => :user_registration

对此:

post 'account' => 'devise/registrations#create', :as => :user_registration

解决方案#2:

更改此行:

put 'account' => 'devise/registrations#update'

对此:

put 'account' => 'devise/registrations#update', :as => :update_user_registration

然后在视图中更改form_for url选项:

form_for(resource, :as => resource_name, :url => update_user_registration_path, :html => { :method => :put })