omniauth身份不能在simple_form_for上与heroku一起工作 [英] omniauth identity not working on heroku with simple_form_for
问题描述
ActionController :: RoutingError(没有路由匹配[POST]/ auth / identity / register):
我有以下的开发工作。
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 / registerdo | f | %GT;<字段集>
< legend><%= controller.action_name.capitalize%>用户LT; /图例>
<%= 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'取消',users_path,:class => 'btn'%>
< / div>< / fieldset><%end%>
routes.rb
匹配/ auth /:service / callback=> 'services#create'
match/ auth / failure=> 'services#failure'
resources:users
这一切在我的机器上完美运行,但是Heroku不喜欢它。
environments / development.rb和production.rb是使用rails new ...创建的默认值,添加了以下内容: -
$ b $
Rails.application.config.middleware.use OmniAuth :: Builder做
需要'openid / store / filesystem'
provider:identity,fields:[:name,:电子邮件],
模型:用户,
on_failed_registration:lambda {| env |
UsersController.action(:new).call(env)
}
#generic openid
provider:open_id,:store => OpenID :: Store :: Filesystem.new('./ tmp'),:name => 'openid'end
希望这一切都有意义,并且有人有答案。任何和所有帮助非常感激。
问候
我找到了答案,只是不确定为什么这样。如果我在这里没有找到stackoverflow,可能会是另一个问题。
无论如何,我正在关注 www.communityguides.eu 并将omniauth配置放在development.rb和production.rb中。这与OpenID :: Store路径不同的是非常有意义的: - $ / $>
development.rb
OpenID :: Store :: Filesystem.new('/ tmp')
production.rb
OpenID :: Store :: Filesystem.new('./ tmp')
答案...
将omniauth配置放入初始化程序/ Omniauth.rb中
这意味着我现在必须每隔一段时间更改一次该文件当我推到Heroku时,Heroku感谢我,并允许我的应用程序很好地运行。
这个问题对我而言(我确信在其他地方有答案)。 Heroku和我们的开发环境的加载顺序有什么不同? Heroku似乎在环境配置之前加载初始化程序。还有一个......任何人都知道一个解决方法,每次我想推到Heroku时,都不必更新Omniauth初始化文件。 :)
感谢Thanx,我希望这有助于节省时间。
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
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.
这篇关于omniauth身份不能在simple_form_for上与heroku一起工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!