Need some help with this please.
I have a model Photos that has a column zone_id and category_id.
Photos with categories and Photos with views render the same index view (photos index).
I want to have a sidebar, depending on if you are in a Photo index by views or in a Photo index by category shows one dropdown or another.
So, if you click on Photo by Modern category, I want the sidebar to render a dropdown "Search by Zone"
In the other case, If you are in Photos index view by zone, I want my side bat to render a dropdown "Search by category".
I know this is with an if / unless, but don't know how to tell the conditional "Hey dude, Im in Photos by category, so you need to render Photos Zone dropdown".
Please help!
Photos Controller
def type
@photos = Photo.by_category(params[:category_id]).paginate(:page => params[:page])
render :index
end
def zone
@photos = Photo.by_zone(params[:zone_id]).paginate(:page => params[:page])
render :index
end
# I've got rid of Photo.with_user_avatar ...
def search
@photos = Photo.all
@photos = @photos.where('category_id = ?', params[:category_id]) if params[:category_id]
@photos = @photos.where('zone_id = ?', params[:zone_id]) if params[:zone_id]
@photos = @photos.paginate(:page => params[:page])
render :index
end
Routes
get 'spots/:category_id', to: "photos#type", as: :spots_category
get 'spots/zonas/:zone_id', to: "photos#zone", as: :spots_zone
get 'spots/:category_id/:zone_id', to: "photos#search", as: :spots_category_zone
get 'spots/zonas/:zone_id/:category_id', to: "photos#search", as: :spots_zone_category
Photos Index View
<% if @photos.first.zone %>
<h6 class="bold medium uppercase grey">Seleccionar estilo para: </br>
<span class="green big"><%= (@photos.first.zone.name ? "#{@photos.first.zone.name}": "") %></h6></span>
<!-- One dropdown-->
<ul class="listnone bold lightgrey">
<li><%= link_to "Moderno", spots_category_zone_path(1,@photos.first.zone) %>
<span class="spot_count small right"><%= @photos.count %></span></li>
<li><%= link_to "Clásico", spots_category_zone_path(2,@photos.first.zone) %>
<span class="spot_count small right"><%= @photos.count %></span></li>
<li><%= link_to "Industrial & Loft", spots_category_zone_path(3,@photos.first.zone) %>
<span class="spot_count small right"><%= @photos.count %></span></li>
<li><%= link_to "Minimalista", spots_category_zone_path(4,@photos.first.zone) %>
<span class="spot_count small right"><%= @photos.count %></span></li>
<li><%= link_to "Rústico", spots_category_zone_path(5,@photos.first.zone) %>
<span class="spot_count small right"><%= @photos.count %></span></li>
<li><%= link_to "Contemporáneo", spots_category_zone_path(6,@photos.first.zone) %>
<span class="spot_count small right"><%= @photos.count %></span></li>
<li><%= link_to "Étnico", spots_category_zone_path(7,@photos.first.zone) %>
<span class="spot_count small right"><%= @photos.count %></span></li>
<li><%= link_to "Art Deco", spots_category_zone_path(8,@photos.first.zone) %>
<span class="spot_count small right"><%= @photos.count %></span></li>
<li><%= link_to "Ecléctico", spots_category_zone_path(9,@photos.first.zone) %>
<span class="spot_count small right"><%= @photos.count %></span></li>
</ul>
<% else %>
<!-- The other dropdown -->
<a href="#" data-dropdown="drop1" data-options="align:right" class="button dropdown"></i> Quiero ver spots de...</a><br>
<ul id="drop1" data-dropdown-content class="f-dropdown" data-options="align:right">
<li><%= link_to "Baños", spots_zone_path(1) %></li>
<li><%= link_to "Cocinas", spots_zone_path(2) %></li>
<li><%= link_to "Cuartos de estar", spots_zone_path(3) %></li>
<li><%= link_to "Dormitorios", spots_zone_path(4) %></li>
<li><%= link_to "Exteriores", spots_zone_path(5) %></li>
<li><%= link_to "Hostelería", spots_zone_path(6) %></li>
<li><%= link_to "Infantil", spots_zone_path(7) %></li>
<li><%= link_to "Oficinas", spots_zone_path(8) %></li>
<li><%= link_to "Salones", spots_zone_path(9) %></li>
</ul>
<% end %>
Thanks a lot!