mardi 4 août 2015

Whats a better way to add conditional input to views in rails?

I have a preview view of a page that I'm building up with a step by step form. Currently the preview view doesn't work, all it has is a default page with default text and styling. My task is to get the preview to display as a user submits the elements of the page through the form. This is what the default view would look like:

<h1>
  Worlds coolest Product
</h1>

<h3>
Buy me and make your life 10x more worthwhile! :)
</h3>

and this default text is rendered out by a partial that looks like this:

<%= render 'manage/deal_steps/deal/main_header' %>

...

My problem is that I need to replace the default text with the user submitted text if there is any but I also need to keep the default text just in case the user doesn't submit any thing. This way I will not get any errors if there is no input. Keeping it simple, Is there any way to achieve this effect without littering the view with conditional logic like this:

<h1>
  <%if retrieve_content('header')!= nil %>
  <%= retrieve_content('header')%>
  <%else%>
  Worlds coolest Product
  <% end%>
</h1>

<h3>
<%if retrieve_content('header_two')!= nil %>
  <%= retrieve_content('header_two')%>
<%else%>
Buy me and make your life 10x more worthwhile! :)
<%end%>
</h3>



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire