尝试将 content_for 更改为部分并获取“未定义的局部变量或方法资源...”
我目前的设备登录表单是这样设置的。我想将此内容放在部分内容(名为 views/devise/sessions/_new.html.erb
而不是 views/devise/sessions/new.html)中,而不是 content_for。 erb
)将在布局中呈现。但是当我这样做时,我得到了
#<#
<% 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 %>
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 %>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它抱怨它不知道您传递给
form_for
的局部变量。您需要向您的部分传递一个名为资源的局部变量,或者将其设置为控制器中的实例变量。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.