Ruby rails 设计表单助手

Ruby on rails devise form helper

我从 ruby 和 rails 开始,我想创建一个助手来显示此表单:

<%= form_for( :user, :url => session_path( :user) ) do |f| %>
  <%= f.text_field :email %>
  <%= f.password_field :password %>
  <%= f.check_box :remember_me %>
  <%= f.label :remember_me %>
  <%= f.submit 'Sign in' %>
  <%= link_to "Forgot your password?", new_password_path( :user) %>
<% end %>

所以我只需要调用函数 show_login_form 并显示表单,但我不知道该怎么做。

谢谢

您可以使用 #concat 辅助方法。

将以下方法放在一些助手中:

def show_login_form
  form_for(:user, :url => session_path( :user) ) do |f|
    concat f.text_field :email
    concat f.password_field :password
    concat f.check_box :remember_me
    concat f.label :remember_me
    concat f.submit 'Sign in'
    concat link_to "Forgot your password?", new_password_path( :user)
  end
end

并从你的观点中称他为:

<%= show_login_form %>