简体   繁体   中英

Customizing redirect after sign up - no error but page does not redirect

I'm using rails 4 and trying to change where my app redirects to after signing up. I followed the instructions on the github page and my registrations controller looks like this:

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

I've also modified my routes:

Rails.application.routes.draw do

  devise_for :users, controllers: {:registrations => "registrations"}

  ....

  get 'paypal_confirmation', to: 'static_pages#paypal_confirmation'

  root 'posts#show_all'
end

And my sign up form looks like this:

<%= 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 %>

When I click the submit button a user is successfully signed up but the page does not redirect. Looking at my server logs I see this message:

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)

As far as I can tell there's no errors being logged so I'm really confused as to why the page doesn't redirect. Any help would be much appreciated.

I see your problem. The problem is in your form. you put remote: true in your form. so its rendering you js template.

Just remove remote: true from this line :

<%= form_for(resource, remote: true, as: resource_name, url: registration_path(resource_name)) do |f| %>

Thanks

The problem is with remote:true on your form. And it executing paypal_confirmation.js.erb code . You can remove remote true or make specific changes in confirmation.js.erb to gid of this.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM