我正在使用rails 4并尝试在注册后更改我的应用重定向到的位置。我按照github page上的说明操作,我的注册控制器如下所示:
class RegistrationsController < Devise::RegistrationsController
before_filter :configure_permitted_parameters
protected
def configure_permitted_parameters
devise_parameter_sanitizer.for(:sign_up) do |u|
u.permit(params listed here)
end
devise_parameter_sanitizer.for(:account_update) do |u|
u.permit(params listed here)
end
end
def after_sign_up_path_for(resource)
paypal_confirmation_path
end
end
我也修改过我的路线:
Rails.application.routes.draw do
devise_for :users, controllers: {:registrations => "registrations"}
....
get 'paypal_confirmation', to: 'static_pages#paypal_confirmation'
root 'posts#show_all'
end
我的注册表格如下:
<%= form_for(resource, remote: true, as: resource_name, url: registration_path(resource_name)) do |f| %>
<%= devise_error_messages! %>
....all the form fields....
<%= f.submit "Confirm with PayPal", :class=>"button button-green button-login" %>
<% end %>
单击“提交”按钮时,用户已成功注册,但页面未重定向。查看我的服务器日志,我看到了这样的消息:
Started GET "/paypal_confirmation" for 192.168.1.13 at 2014-08-13 07:36:27 +0100
Processing by StaticPagesController#paypal_confirmation as JS
Rendered static_pages/paypal_confirmation.html.erb within layouts/application (0.1ms)
User Load (4.2ms) SELECT "users".* FROM "users" WHERE "users"."id" = 10 ORDER BY "users"."id" ASC LIMIT 1
Completed 200 OK in 1109ms (Views: 1103.9ms | ActiveRecord: 4.2ms)
据我所知,没有记录错误所以我真的很困惑为什么页面没有重定向。任何帮助将非常感激。
答案 0 :(得分:0)
我看到了你的问题。问题出在你的身上。你把remote: true
放在表格中。所以它渲染你js模板。
只需从此行中删除remote: true
:
<%= form_for(resource, remote: true, as: resource_name, url: registration_path(resource_name)) do |f| %>
由于
答案 1 :(得分:0)
问题出在remote:您的表单上为true。它执行paypal_confirmation.js.erb代码。您可以删除remote true或在confirmation.js.erb中进行特定更改以获取此信息。