Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community!

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby

Brian Gilbank
Brian Gilbank
9,586 Points

different email subscribe button.

I have an email subscribe form that needs to use a different style of button depending on which view/page the form is placed on. How would this be best achieved?

I am assuming an if/else statement.

 <%= form_for(@email) do |f| %>

  <% if @email.errors.any? %>
    <div id="error_explanation">
      <h2><%= pluralize(@email.errors.count, "error") %> prohibited this email from being saved:</h2>

      <ul>
      <% @email.errors.full_messages.each do |message| %>
        <li><%= message %></li>
      <% end %>
      </ul>
    </div>
  <% end %>
                        <div class="field-wrapper">
                          <%= f.text_field :email, required: true, class: "form-email form-element", placeholder: "Email address", :tabindex => 2 %>
                        </div>
                      </div>
                      <% if some_condition_is_met  %> 
                      <div class="column width-3">
                        <%= f.submit 'submit', class: "form-submit button bkg-charcoal bkg-hover-theme color-white color-hover-white" %>
                      </div>
                     <% else %>
                     <div class="column width-4">  
                        <%= f.submit 'submit', class: "form-submit button border-grey bkg-hover-grey color-white color-hover-white" %>
                      </div>
                       <% end %>
                    </div>
                    <% end %>