Note that there are some explanatory texts on larger screens.

plurals
  1. POMethod to return multiple bits of text Rails
    primarykey
    data
    text
    <p>I am currrently in the process of writing a new rails application and have a div near the top of my page called background that contains an image, a Title and some sub title text. </p> <p>At the moment I have created seperate helper methods, as below, that passes in each of the elements by testing against the action and controller parameter. </p> <p>This doesn't however seem like a very efficient way of implementing the code and so I was wondering what would be the best way to pass the three elements together in one method?</p> <p>Currently I have a setup like this:</p> <pre><code>def background if params[:action] == "index" &amp;&amp; params[:controller] == "everydays" return "/assets/everyday.jpg" elsif params[:action] == "index" &amp;&amp; params[:controller] == "mens" return "/assets/mens.jpg" elsif params[:action] == "index" &amp;&amp; params[:controller] == "womens" return "/assets/womens.jpg" end end def title_h1 if params[:action] == "index" &amp;&amp; params[:controller] == "everydays" return "Everyday" elsif params[:action] == "index" &amp;&amp; params[:controller] == "mens" return "Mens" elsif params[:action] == "index" &amp;&amp; params[:controller] == "womens" return "Womens" end end def title_h3 if params[:action] == "index" &amp;&amp; params[:controller] == "everyday" return "Example text for this Everyday Section" elsif params[:action] == "index" &amp;&amp; params[:controller] == "mens" return "Example text for this Mens Section" elsif params[:action] == "index" &amp;&amp; params[:controller] == "womens" return "Example text for this Womens Section" end end </code></pre> <p>Any advice people can offer would be much appreciated.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload