所以,我遇到了一个有趣的问题。我正在尝试覆盖并将设计 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 %>