用于NilClass的未定义方法`model_name':使用Devise的类

时间:2014-12-15 09:04:32

标签: javascript ruby-on-rails devise

我有一个用户模型。我使用devise进行身份验证。现在有另一个模型类别。用户有许多首选类别。我想显示注册模态,然后选择类别模式。

这就是我的代码的样子

_signup_modal.html.slim

.modal.fade#signupModal tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"
 .modal-dialog
  .modal-content
   .modal-header.text-center
    strong.logo
      a
  = render partial: 'shared/signup_form'

signup_form.html.slim

- resource = User.new unless resource
- resource_name = 'user' unless resource_name
h5.text-center Sign up 

= form_for resource, url: registration_path(resource_name), remote: true, html: { id:  'signup', role: 'form'  } do |f|

.row
  .form-group.col-sm-12
    = f.text_field :email, type: 'email', class: 'form-control', placeholder: "Email Address"
.row
  .form-group.col-sm-12
     = f.password_field :password, value: (params[:user][:password] if params[:user]), class: 'form-control', placeholder: "Password"

.form-group.form-actions
  button.submit-btn.btn type="submit" Sign Up

signup_form.js.erb

 $("body").prepend("<%= escape_javascript(render "shared/subscribe_modal", :formats => [:html]) %>");
 $("#signupModal").modal("hide");
 $("#subscribeModal").modal();

RegistrationsController

class RegistrationsController < Devise::RegistrationsController  

  def create
       build_resource(sign_up_params)

       if resource.save
          if resource.active_for_authentication?
            set_flash_message :notice, :signed_up if is_navigational_format?
            sign_up(resource_name, resource)
          return render 'shared/signup_form'
          else
             set_flash_message :notice, :"signed_up_but_#{resource.inactive_message}"             
           if is_navigational_format?
                expire_session_data_after_sign_in!
               return render 'shared/signup_form'
           end
       else
           clean_up_passwords resource
           return render user_path
   end
end
def edit
  @user=current_user
 end
 def update
  @user=current_user
 puts "#{params[:user_category_ids]}"
 end

end

subscribe_modal.html.slim

 .modal.fade#subscribeModal tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"
 .modal-dialog
 .modal-content
   .modal-header.text-center
     strong.logo
       a
    h5.text-center title
 = form_for @user, url: edit_user_registration_path(@url), remote: true, html: { id: 'subscribe', role: 'form', method: :put  } do |f|
h6 I'm intrested in receiving offers about:

.row
  - Category.all.each do |cat|
    .checkbox.col-sm-6
      /label
        = check_box_tag 'user[category_ids][]', cat.id, false
        span =cat.name


br
button.btn type="submit" Subscribe 

我在_subscribe_modal form_for helper

中获得了undefined method 'model_name' for NilClass:Class

0 个答案:

没有答案