用轨道设计改变路线

时间:2014-09-10 10:17:35

标签: ruby-on-rails devise routes gem

我正在使用rails 4.1.1

我希望用户遵循的旅程是使用基本设计表单进行注册,以便通过电子邮件,密码和密码确认。当用户提交此项时,我希望将它们直接带到编辑个人资料页面。新用户注册页面的底部如下所示。我尝试过一些东西,但一切都让我误回歧途。任何帮助将非常感激!我还包括我的设计链接,因为我认为这是我应该看的地方?

   <div class="form-group">
    <%= f.label :password_confirmation %>
    <%= f.password_field :password_confirmation, autocomplete: "off", class: "form-control" %>
  </div>

  <div class="form-group">
    <%= f.submit "Sign up", class: "btn btn-primary" %>

  </div>
<% end %>

<%= render "devise/shared/links" %>





    <%- if controller_name != 'sessions' %>
  <%= link_to "Log in", new_session_path(resource_name) %><br />
<% end -%>

<%- if devise_mapping.registerable? && controller_name != 'registrations' %>
  <%= link_to "Sign up", new_registration_path(resource_name) %><br />
<% end -%>

<%- if devise_mapping.recoverable? && controller_name != 'passwords' && controller_name != 'registrations' %>
  <%= link_to "Forgot your password?", new_password_path(resource_name) %><br />
<% end -%>

<%- if devise_mapping.confirmable? && controller_name != 'confirmations' %>
  <%= link_to "Didn't receive confirmation instructions?", new_confirmation_path(resource_name) %><br />
<% end -%>

<%- if devise_mapping.lockable? && resource_class.unlock_strategy_enabled?(:email) && controller_name != 'unlocks' %>
  <%= link_to "Didn't receive unlock instructions?", new_unlock_path(resource_name) %><br />
<% end -%>

<%- if devise_mapping.omniauthable? %>
  <%- resource_class.omniauth_providers.each do |provider| %>
    <%= link_to "Sign in with #{provider.to_s.titleize}", omniauth_authorize_path(resource_name, provider) %><br />
  <% end -%>
<% end -%>

路线如下

      new_admin_user_session GET        /admin/login(.:format)                     active_admin/devise/sessions#new
            admin_user_session POST       /admin/login(.:format)                     active_admin/devise/sessions#create
    destroy_admin_user_session DELETE|GET /admin/logout(.:format)                    active_admin/devise/sessions#destroy
           admin_user_password POST       /admin/password(.:format)                  active_admin/devise/passwords#create
       new_admin_user_password GET        /admin/password/new(.:format)              active_admin/devise/passwords#new
      edit_admin_user_password GET        /admin/password/edit(.:format)             active_admin/devise/passwords#edit
batch_action_admin_admin_users POST       /admin/admin_users/batch_action(.:format)  admin/admin_users#batch_action
             admin_admin_users GET        /admin/admin_users(.:format)               admin/admin_users#index
                               POST       /admin/admin_users(.:format)               admin/admin_users#create
          new_admin_admin_user GET        /admin/admin_users/new(.:format)           admin/admin_users#new
         edit_admin_admin_user GET        /admin/admin_users/:id/edit(.:format)      admin/admin_users#edit
              admin_admin_user GET        /admin/admin_users/:id(.:format)           admin/admin_users#show
                               PATCH      /admin/admin_users/:id(.:format)           admin/admin_users#update
                               PUT        /admin/admin_users/:id(.:format)           admin/admin_users#update
                               DELETE     /admin/admin_users/:id(.:format)           admin/admin_users#destroy
              new_user_session GET        /users/sign_in(.:format)                   devise/sessions#new
                  user_session POST       /users/sign_in(.:format)                   devise/sessions#create
          destroy_user_session DELETE     /users/sign_out(.:format)                  devise/sessions#destroy
                 user_password POST       /users/password(.:format)                  devise/passwords#create
             new_user_password GET        /users/password/new(.:format)              devise/passwords#new
            edit_user_password GET        /users/password/edit(.:format)             devise/passwords#edit
                               PATCH      /users/password(.:format)                  devise/passwords#update
                               PUT        /users/password(.:format)                  devise/passwords#update
      cancel_user_registration GET        /users/cancel(.:format)                    devise/registrations#cancel
             user_registration POST       /users(.:format)                           devise/registrations#create
         new_user_registration GET        /users/sign_up(.:format)                   devise/registrations#new
        edit_user_registration GET        /users/edit(.:format)                      devise/registrations#edit
                               PATCH      /users(.:format)                           devise/registrations#update
                               PUT        /users(.:format)                           devise/registrations#update
                               DELETE     /users(.:format)                           devise/registrations#destroy

这是我的应用程序控制器

    class ApplicationController < ActionController::Base
  # Prevent CSRF attacks by raising an exception.
  # For APIs, you may want to use :null_session instead.
  protect_from_forgery with: :exception

   before_filter :configure_permitted_parameters, if: :devise_controller?

  protected

  def configure_permitted_parameters
    devise_parameter_sanitizer.for(:sign_up) { |u| u.permit(:name, :email, :password) }
    devise_parameter_sanitizer.for(:account_update) { |u| u.permit(:name, :line1, :line2, :town, :county, :postcode)}
  end

  private 
  def after_sign_up_path_for(resource)
    edit_user_registration_path
  end
end

1 个答案:

答案 0 :(得分:1)

为了能够更改after sign_up行为,您必须覆盖after_sign_up_path_for中的设计application_controller.rb方法:

class ApplicationController < ActionController::Base

  private
  def after_sign_up_path_for(resource)
    edit_user_registration_path(current_user) #basically whichever path you think meets your needs
  end
end