简体   繁体   中英

Ruby on Rails - error when trying to render a devise login form

I have this haml file:

= content_for :page_title do
  = t :page_title_login
= content_for :primary_content do
  #login_box
    .span6
      #traditional-login
        %hgroup
          %h3= t :heading_account_login
        = render "devise/sessions/form"

    .span4

= content_for :before_closing_body_tag do
  configure_login_form(#{request.xhr?.to_s.downcase});

it is located in my app/views/mobile/sessions/new.haml.html path.

It gives this error:

Showing /Users/alexgenadinik/projects/cmply/cmply-app/app/views/devise/sessions/_form.html.haml where line #1 raised:

undefined local variable or method `resource' for #<#<Class:0x148213358>:0x14820dac0>

but when I comment out this line:

= render "devise/sessions/form"

it renders the page but without the actual form. So I think I need that line, I am just not sure how to add that line back in without getting the error.

Here is my controller:

class Mobile::SessionsController < ApplicationController
  def create
    redirect_to home

  end

  def new
    redirect_to home
  end
end

Any idea what I might be doing wrong?

Thanks!!

that form partial makes use of a local variable resource which it can not find.

You have to pass that variable along to the render call.

= render "devise/sessions/form", :locals => {:resource => resource}

You might also be missing other variables. My new.html.haml mentions also resource_name and devise_mapping . Maybe you have to pass those vars too.

Take a look at rendering partials documentation.

BTW, your HAML should have - content_for not = content_for , because that is a control-call .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM