简体   繁体   English

Ruby on Rails-尝试呈现设计登录表单时出错

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

I have this haml file: 我有这个haml文件:

= 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. 它位于我的app/views/mobile/sessions/new.haml.html路径中。

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. 局部形式使用了它找不到的局部变量resource

You have to pass that variable along to the render call. 您必须将该变量传递给render调用。

= 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 . 我的new.html.haml还提到了resource_namedevise_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 . 顺便说一句,您的HAML应该具有- content_for not = content_for ,因为这是一个控制调用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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