2017-07-02 144 views
-3

我開始用Ruby和Rails,我想創建一個輔助顯示這種形式:Ruby on 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和顯示形式,但我不知道如何。

感謝

回答

0

您可以使用#concat helper方法。在一些輔助

認沽以下方法:

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

謝謝你的工作! – Juanpi