Suppose, I have a model called Animal. This model contains enum attribute kind with two possible states.
class Animal < ActiveRecord::Base
enum kind: [ :cat, :dog ]
end
Then in my controller I create corresponding instance variables collections.
class AnimalsController < ApplicationController
def index
@cats = Animal.cat
@dogs = Animal.dog
end
end
In my view I got two links and two collections.
<h1>Animals</h1>
<b><%= link_to 'List Cats' %></b>
<b><%= link_to 'List Dogs' %></b>
<%= render partial: 'animals/cat', collection: @cats, as: :cat %>
<%= render partial: 'animals/dog', collection: @dogs, as: :dog %>
What is the prefered way of displaying first collection instead of second or second one instead of the first in the same place depending on clicked link? How to do that?
Aucun commentaire:
Enregistrer un commentaire