Rails 4设计3.1.1 ActionController :: Devise中的UnknownFormat :: RegistrationsController #new

时间:2013-10-05 02:02:28

标签: ruby-on-rails ruby devise ruby-on-rails-4

我正在使用Devise 3.1.1开发用于用户身份验证的Rails 4应用程序。当我单击/users/sign_up.user链接时,Rails会抛出以下异常:

ActionController::UnknownFormat in Devise::RegistrationsController#new
ActionController::UnknownFormat

Rails.root: /home/rehan/odesk_work/kiefer-waight/ujoin/ujoin-www

Application Trace | Framework Trace | Full Trace
actionpack (4.0.0) lib/action_controller/metal/mime_responds.rb:372:in `retrieve_collector_from_mimes'
actionpack (4.0.0) lib/action_controller/metal/mime_responds.rb:327:in `respond_with'
devise (3.1.1) app/controllers/devise/registrations_controller.rb:8:in `new'
actionpack (4.0.0) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
actionpack (4.0.0) lib/abstract_controller/base.rb:189:in `process_action'
actionpack (4.0.0) lib/action_controller/metal/rendering.rb:10:in `process_action'
actionpack (4.0.0) lib/abstract_controller/callbacks.rb:18:in `block in process_action'
activesupport (4.0.0) lib/active_support/callbacks.rb:413:in `_run__890637270__process_action__callbacks'
....

我在启动应用程序时实际上是在Devise 3.0.0.rc上,我认为将设备升级到3.1.1可能会解决问题,但事实并非如此。在SO / google / devise github项目中找不到任何有用的东西。任何想法如何解决它。谢谢!

4 个答案:

答案 0 :(得分:13)

我不想更改Devise生成的默认链接,在每个链接的末尾添加“.user”。设计产生以下链接:

new_user_registration_path(resource_name) new_user_session_path(resource_name) new_user_password_path(resource_name)

resource_name,用户,作为link_to方法中路径的参数,告诉它使用“.user”作为格式。所以我刚从每个路径中删除了resource_name。我想知道为什么Devise会这样做!

答案 1 :(得分:3)

@ zeeshan的答案有效,你也可以没有_user中缀的函数:

new_registration_path(resource_name)

new_session_path(resource_name)

new_password_path(resource_name)

答案 2 :(得分:1)

I've just resolved this problem also.

The solution is to revert all paths to Devise default ones, meaning to say no _user infix.

Note that we are not able to test in console these code:

user = User.all.sample
app.new_registration_path(user)

because Devise use its helper to transform the url automatically internally so we cannot test from outside.

答案 3 :(得分:0)

当您说您点击/users/sign_up.user链接时,您的字面意思是确切路径吗?因为最后的.user告诉它尝试使用user格式进行回复,类似于pdfxmljson。删除它,看看会发生什么。