设计在rails 3.1中抛出ArgumentError

时间:2011-10-04 01:39:58

标签: ruby-on-rails-3 devise ruby-on-rails-3.1

在Rails 3.1应用程序和更新的Devise 1.4.7中,当我访问http://localhost:3000/users/sign_up时(如rake路由中所示),我得到“设计错误在设计/注册#new ”提取源是第3行:

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

这是什么解决方案?提前谢谢。

Deals::Application.routes.draw do
  devise_for :users
  root :to => "home#index"
end

3 个答案:

答案 0 :(得分:0)

你有太多的论据。 form_for只需要一个参数(资源),如下所示:

@registration = Registration.new
form_for @registration

如果需要,您可以选择传递:url

答案 1 :(得分:0)

试试这个。

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

答案 2 :(得分:0)

我可以确认当您运行rails generate devise:views并查看从gem复制到 app / views / devise / registrations / new.html.erb 的工作默认模板时,{{ Devise使用参数调用3}}:

form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f|

如果您希望复制gem视图,请查看form_for

但是,如果您(或其他人正在阅读此内容)尝试将注册表单与您自己的控制器一起使用,则完全有可能需要重新创建一些方法the views in the repo以便from the Devise controller 。假设您调用了用户类User

def resource_name
  :user
end

def resource
  @resource ||= User.new
end

def devise_mapping
  @devise_mapping ||= Devise.mappings[:user]
end
相关问题