user852974
user852974

Reputation: 2282

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

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 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 %>

Upvotes: 0

Views: 612

Answers (1)

Peter Brown
Peter Brown

Reputation: 51697

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.

Upvotes: 2

Related Questions