Simple_form中未定义的方法`model_name'

时间:2013-09-02 13:15:31

标签: ruby-on-rails ruby-on-rails-4 simple-form

所以我有两步Twitter登录,在用户必须输入电子邮件的页面上,我得到一个未定义的方法错误。

我的表格

<%= simple_form_for(@user, :as => "user", :url => account_create_path, :html => {:class => "form-inline"}) do |f| %>
  <%= f.input :email, :placeholder => User.human_attribute_name(:email), :class => "input-medium" %>
  <%= f.submit "Finish registration", :class => "btn btn-small" %>
<% end %>

我认为这是一个语法问题,但由于我对Rails相当新,我无法弄清楚出了什么问题。谷歌也不会告诉我:)

我的 Accounts_controller.rb

def create
        data = session["devise.omniauth_data"]
        data[:email] = params[:user][:email]
        user = User.find_for_twitter_oauth(data)
        user.email = data[:email]

        if user.save
            flash[:notice] = I18n.t "devise.registrations.signed_up_but_unconfirmed"
            redirect_to root_path
        else
            flash[:error] = I18n.t "devise.omniauth_callbacks.failure",
                                                         :kind => data[:provider].titleize,
                                                         :reason => user.errors.full_messages.first
            render "users/omniauth_callbacks/add_email"
        end
    end

enter image description here

1 个答案:

答案 0 :(得分:1)

将变量user更改为控制器中的实例变量@user,问题将得到解决。