I'm posting reviews for Amazon products since it's become a crapshoot if you're getting a legit product or cheap garbage straight from China. If the product is legit, I want the Amazon 'buy' image (that's linked to the item) to appear. If it's garbage, I want a different Amazon image to appear (a greyed out one).
I have 'verdict' and 'goodverdict' fields in my new product form. But atm only verdict is in use, and the Amazon buy image is always there (these two are not related right now).
What I've been trying to do is set it up so if I fill out the 'goodverdict' field, the buy image shows (with a link). Conversely, if I use the regular 'verdict' field and leave 'goodverdict' blank, then the greyed out image shows.
I think all I'm missing is an if/else statement?
I removed any styling, but this is the verdict showing and under it, the buy image that's linked to the product (I paste that 'buylink' link into the form). This is in a partial that renders on the product show page.
<div>
<h1><%= @product.verdict %></h1><br>
<%= link_to image_tag("http://ift.tt/2mdupO6"), @product.buylink.html_safe %>
</div>
If you want to see the form fields:
<div class="form-group">
<%= f.label :buylink %>
<%= f.text_field :buylink, class: "form-control" %>
</div>
<div class="form-group">
<%= f.label :verdict %>
<%= f.text_field :verdict, class: "form-control" %>
</div>
<div class="form-group">
<%= f.label :goodverdict %>
<%= f.text_field :goodverdict, class: "form-control" %>
</div>
I'm open to alternative ways of doing this, like a checkbox for "crap" or "legit" being what controls if the buy image shows. I welcome all good advice. Thank you in advance.
Aucun commentaire:
Enregistrer un commentaire