问题
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