Rails 3:奇怪的设计重定向错误

时间:2012-09-13 01:27:18

标签: ruby-on-rails ruby-on-rails-3 devise routes mongoid

所以,我遇到了一个有趣的问题。我试图覆盖并将设计sign_up和sign_in请求重定向到相应的配置文件页面,但我遇到了错误。配置文件和URL通过控制台,link_to或键入来访问它。由于某种原因,设计方法不会路由到它。我不知道为什么。无论如何,为所有贡献或解决的人提供赞成。谢谢!

路线:

  root :to => 'pages#index'
  get "pages/index"

  devise_for :users, :path => 'accounts', :controllers => { :registrations => "registrations" }

  get 'users/:id/profile' => 'profiles#show', :as => 'current_profile'
  get 'users/:id/profile/edit' => 'profiles#edit', :as => 'edit_current_profile'
  put 'users/:id/profile' => 'profiles#update'

  resources :users do
    resources :profiles 
  end

注册控制器:

class RegistrationsController < Devise::RegistrationsController

  protected

  def after_sign_up_path_for(resource)
     edit_current_profile_path(resource)
  end

  def after_sign_in_path_for(resource)
     current_profile_path(resource)
  end

end

个人资料控制器

  def show
    @user = current_user
    @profile = @user.profile

    respond_to do |format|
      format.html 
    end
  end

错误讯息:

Routing Error

No route matches {:controller=>"profiles", :action=>"show"}
Try running rake routes for more information on available routes.

查看:edit.html.erb

<%= form_for([@profile.user, @profile]) do |f| %>
  <% if @profile.errors.any? %>
    <div id="error_explanation">
      <h2><%= pluralize(@profile.errors.count, "error") %> prohibited this profile from being saved:</h2>

      <ul>
      <% @profile.errors.full_messages.each do |msg| %>
        <li><%= msg %></li>
      <% end %>
      </ul>
    </div>
  <% end %>

  <div class="field">
    <%= f.label :real_name %><br />
    <%= f.text_field :real_name %>
  </div>
  <div class="actions">
    <%= f.submit %>
  </div>
<% end %>

1 个答案:

答案 0 :(得分:1)

您应该为路线助手提供属性。试一试

def after_sign_up_path_for(resource)
   edit_current_profile_path(resource)
end

def after_sign_in_path_for(resource)
   current_profile_path(resource) 
end