omniauth identity not working on heroku with simple_form_for

ぃ、小莉子 提交于 2019-12-08 11:50:25

问题


I'm having trouble with Heroku not playing ball and throwing me this error

ActionController::RoutingError (No route matches [POST] "/auth/identity/register"):

I have the following working in dev.

model/user.rb

class User < OmniAuth::Identity::Models::ActiveRecord
  has_many :services

controllers/users_controller.rb

def new
  @user = env['omniauth.identity'] || User.new
end

users/new.html.erb

<%= simple_form_for @user, url: "/auth/identity/register" do |f| %><fieldset>
<legend><%= controller.action_name.capitalize %> User</legend>
<%= f.input :name, input_html: { name: "name" } %>
<%= f.input :email, input_html: { name: "email" } %>
<%= f.input :password, input_html: { name: "password" } %>
<%= f.input :password_confirmation, input_html: { name: "password_confirmation" } %>
<div class="form-actions">
  <%= f.button :submit %>
  <%= link_to 'Cancel', users_path, :class => 'btn' %>
</div></fieldset><% end %>

routes.rb

match "/auth/:service/callback" => 'services#create'
match "/auth/failure" => 'services#failure'
resources :users

This all works Perfectly on my machine but Heroku doesn't like it. environments/development.rb and production.rb are the defaults created with "rails new..." with the following added:-

Rails.application.config.middleware.use OmniAuth::Builder do
require 'openid/store/filesystem'

provider :identity, fields: [:name, :email],
                    model: User,
                    on_failed_registration: lambda { |env|
                      UsersController.action(:new).call(env)
                    }

# generic openid
provider :open_id, :store => OpenID::Store::Filesystem.new('./tmp'), :name => 'openid'end

Hope this all makes sense and someone has the answer. Any and all help muchly appreciated.

Regards


回答1:


Ok, I found the answer, just not sure why this is so though. Could be another question later if I don't find it here in stackoverflow.

Anyways, I was following this Excellent guide on www.communityguides.eu and put the omniauth configurations in development.rb and production.rb. Which made perfect sense as the OpenID::Store paths were different being:-

development.rb OpenID::Store::Filesystem.new('/tmp')

production.rb OpenID::Store::Filesystem.new('./tmp')

The Answer... Put the omniauth configurations in initializers/Omniauth.rb

This means I now have to change this file every time I push to Heroku, but Heroku thanks me and allows my app to run nicely.

The question this raises for me (which I'm sure is answered elsewhere). What is the difference in the load order from Heroku and our Dev environments? Heroku appears to be loading initializers before the environment configs. And one more...anyone know a workaround that will save me having to update the Omniauth initializer file every time I want to push to Heroku ? :)

Thanx for reading and I hope this helps save someone some time.



来源:https://stackoverflow.com/questions/9953672/omniauth-identity-not-working-on-heroku-with-simple-form-for

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!