i have following code in edit view:
<%= form_for @content |f|%> <% if f.text_field :home %> <%= f.label :home %> <%= f.text_field :home %> <% elsif f.text_field :aboutus %> <%= f.label :abouts %> <%= f.text_field :aboutus %> <% end %> <%= f.submit%> here @content contain following information:
id: "1", home: "staticcontent", aboutus: "staticcontent" so wants if wants edit home page can see home submission form , if choose aboutus, can see edit form page us.suggest me whats correct way use if,else in block?
you pass url param , work that. example:
# in view <%= link_to "edit homepage", edit_content_path(page: "home") # link /contents/:id/edit?page=home then in form:
<%= form_for @content |f|%> <% if params[:page] == "home" %> <%= f.label :home %> <%= f.text_field :home %> <% else %> <%= f.label :about_us %> <%= f.text_field :about_us %> <% end %> <%= f.submit%> notice downcased labels, , changed aboutus about_us label displays correctly.
Comments
Post a Comment