Forum: Ruby on Rails <% unless params[:context] == :gallery -%> question

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
73606b1d1042de19056f3d59492b652f?d=identicon&s=25 charlie bowman (Guest)
on 2005-12-19 03:29
I have a template that is called by two different methods.  I only want
part of it too show up when it is called from one of the methods.  It
always shows up for me.  Can someone help to point out my error?  Below
is the method that should keep part of the tempate from printing, and
the relevent part of the template.

method:
  def gallery
    @product_pages,@products = paginate(:products, :per_page  => 12,
:conditions => "sold != 'current'")
    render( :template   => "store/index",
            :params     =>  { :context  => :gallery})
  end

template:
            <% unless params[:context] == :gallery -%>
            <span id="product_price"><%= @products[0].price %></span><br
/>
            <span id="cart_link"> <%= link_to 'Add to Cart',
                    {:action => 'add_to_cart', :id => product },
                    :class => 'addtocart' %><br/>
            </span>
            <% end -%>
B7aa6f0356566cc801f769c6fc14ba1a?d=identicon&s=25 Francois GORET (Guest)
on 2005-12-19 08:28
(Received via mailing list)
Hello,

in the controller, try:
@context = :gallery
render :template => "store/index"

and in the template
<% unless @context == :gallery -%>

There's a :locals option for render, but it seems that it works only for
rendering partials.
This topic is locked and can not be replied to.