开发者

Trying to change content_for into a partial and getting "undefined local variable or method resource ..."

开发者 https://www.devze.com 2023-04-06 12:13 出处:网络
I currently have my devise login form set up like this. Instead of content_for, I would like to just put this content in a partial (named views/devise/sessions/_new.html.erb instead of views/devise/se

I currently have my devise login form set up like this. Instead of content_for, I would like to just put this content in a partial (named views/devise/sessions/_new.html.erb instead of views/devise/sessions/new.html.erb) to be rendered in the layout. But when I do, I get

undefined local variable or method resource for #<#<Class:0x0000010300f6f0>:0x0000010300da30>

<% content_for :header do %>
    <div id="login">
        <%= form_for(resource, :as => resource_name, :url => session_path(resource_name)) do |f| %>
          <div class="login_header"><%= f.email_field :email, :placeholder => "Email" %></div>

          <div class="login_header"><%= f.password_field :password, :placeholder => "Password" %></div>

          <% if devise_mapping.rememberable? -%>
            <div开发者_如何学JAVA class="login_header"><%= f.check_box :remember_me %> <%= f.label :Stay_logged_in %></div>
          <% end -%>

          <div class="login_header"><%= f.submit "Sign in" %></div>
        <% end %>
        <br /><br />
        <%= render :partial => "devise/shared/links" %>
    </div>
<% end %>


It's complaining that it doesn't know about a local variable that you're passing to form_for. You need to pass your partial a local variable called resource or set it as an instance variable in the controller.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号