validate_uniqueness_of scope not working - ruby-on-rails

Currently I can create one item with multiple designs in unique picturelocs. Creating a second item gives me the following error that there already exists a pictureloc with that value, even though it is in a seperate item_id and shouldn't be worried over. This is my first question so cut me some slack on the formatting, and thanks in advance!
Error:
PG::Error: ERROR: duplicate key value violates unique constraint "index_designs_on_pictureloc"
DETAIL: Key (pictureloc)=(1) already exists.
: INSERT INTO "designs" ("created_at", "item_id", "picture_content_type", "picture_file_name", "picture_file_size", "picture_updated_at", "pictureloc", "updated_at") VALUES ($1, $2, $3, $4, $5, $6, $7, $8) RETURNING "id"
Design.rb
class Design < ActiveRecord::Base
attr_accessible :picture, :pictureloc
has_attached_file :picture, styles: {medium: "150x150#"}
validates_attachment :picture, presence: true,
content_type: { content_type: ['image/jpeg', 'image/jpg', 'image/png'], :message => 'must be a PNG, JPG, or JPEG'},
size: {less_than: 5.megabytes, :message => 'must be less than 5 megabytes'}
validates_uniqueness_of :pictureloc, scope: :item_id
belongs_to :item
def show_location
if pictureloc == 1
"Front"
elsif pictureloc == 2
"Back"
elsif pictureloc == 3
"Left Sleeve"
elsif pictureloc == 4
"Right Sleeve"
end
end
end
Item.rb
class Item < ActiveRecord::Base
attr_accessible :price, :make, :amount, :color, :note, :designs_attributes
validates_presence_of :make, :amount, :color
validates :amount, :numericality => { :greater_than => 0 }
belongs_to :quote
has_many :designs, :dependent => :destroy
accepts_nested_attributes_for :designs
end
Index in the schema:
add_index "designs", ["pictureloc"], :name => "index_designs_on_pictureloc", :unique => true
nested item view:
<!-- item form -->
<%= f.input :make, collection: #types, label: 'Thread Type' %>
<%= f.input :amount, label: 'How Many' %>
<%= f.input :color, collection: #colors %>
<!-- nested form for creating a design of an item -->
<%= f.simple_fields_for :designs, :html => { :multipart => true } do |designform| %>
<%= render "customdesign", g: designform %>
<% end %>
<!-- add/remove another design -->
<%= f.link_to_add "Add Design", :designs %>
<%= f.input :note, :input_html => { :cols => 50, :rows => 3 }, label: 'Special Notes or Requests' %>
<%= f.link_to_remove "Remove" %>
Nested design view:
<!-- upload/remove image form -->
<%= g.select( :pictureloc, { "Front" => 1, "Back" => 2, "Left Sleeve" => 3, "Right Sleeve" => 4 } ) %>
<%= g.file_field :picture %>
<%= g.link_to_remove "Remove" %>
Note that pictureloc is an integer, and that the designs get saved at the same time which is why I had to create an index (I think?)
I tried removing the unique: true from the index because maybe it was overkill, but that didn't solve anything.

Your index should be
add_index "designs", ["pictureloc", "item_id"], :name => "index_designs_on_pictureloc", :unique => tru

Related

Rails 5.2 ActiveAdmin deep nested objects

I have this scheme: Course->Segments->Questions.
Course has many segments and segments has many questions.
I added segment_type attribute to segment model so I can show/hide question model depends on the type (video or quiz).
I managed to write the form in courses.rb and I got access to questions through course.
I'm having a problem with showing question attributes in show page even when I searched 3-4 hours on google for answer. Here is a screenshot of the show page
I wrote accept_nested_attribute in all the models so this is not the problem. I can edit, create and delete courses, segments and questions, it's just I can't see in the show the data relevant to questions.
EDIT: I know that the relations works fine in rails console and I have data in questions (it suppose to display the last segment's questions)
these are my models:
class Course < ApplicationRecord
validates :title ,presence: true
validates :author ,presence: true
has_many :segments, inverse_of: :course, :dependent => :destroy, :autosave => true
accepts_nested_attributes_for :segments, :allow_destroy => true
end
class Segment < ApplicationRecord
validates :course_id ,presence: true
validates :data ,presence: true, if: :segment_is_video?
validates :segment_type ,presence: true
validates_presence_of :course
belongs_to :course
has_many :questions, inverse_of: :segments, :dependent => :destroy, :autosave => true
accepts_nested_attributes_for :questions, :allow_destroy => true
def self.segment_type
{"Video": "Video", "Quiz": "Quiz"}
end
def segment_is_video?
segment_type == 'Video'
end
end
class Question < ApplicationRecord
validates :question ,presence: true
validates :answer1 ,presence: true
validates :answer2 ,presence: true
validates :answer3 ,presence: true
validates :answer4 ,presence: true
validates :correct ,presence: true
validates_presence_of :segment
belongs_to :segment
end
this is courses.rb:
ActiveAdmin.register Course do
permit_params :id, :title, :autor,
segments_attributes: [:id, :unit_id, :unit_title, :name, :segment_type, :data, :_destroy, :_create, :_update, questions_attributes: [:id, :question, :answer1, :answer2, :answer3, :answer4, :correct, :_destroy, :_create, :_update]]
config.sort_order = 'id_asc'
member_action :segments do
#segments = resource.segments
end
index do
column :id
column :title
column :author
actions
end
show do
panel "Course Segments" do
h3 "Videos"
table_for resource.segments.where('segment_type = "Video"') do
column :id
column :name
column :data
end
# Here it's only displaying id and name values, but the others no.
h3 "Quizes"
table_for resource.segments.where('segment_type = "Quiz"') do
column :id
column :name
column :question
column :answer1
column :answer2
column :answer3
column :answer4
column :correct
end
end
active_admin_comments
end
sidebar "Course Details", only: :show do
attributes_table_for course do
row :title
row :author
end
end
form do |f|
tabs do
tab 'Basic Info' do
f.inputs "Course details" do
f.input :title
f.input :author
end
end
tab 'Content' do
f.inputs "Segments" do
f.has_many :segments, heading: false, allow_destroy: true do |s|
s.input :unit_id
s.input :unit_title
s.input :name
s.input :segment_type, as: :select, collection: Segment.segment_type, input_html: { class: 'select-type' }
s.input :data, label: 'Url', :as => :string, input_html: { class: 'video-tab' }
s.has_many :questions, heading: false, allow_destroy: true do |q|
q.input :question, input_html: { class: 'quiz-tab' }
q.input :answer1, input_html: { class: 'quiz-tab' }
q.input :answer2, input_html: { class: 'quiz-tab' }
q.input :answer3, input_html: { class: 'quiz-tab' }
q.input :answer4, input_html: { class: 'quiz-tab' }
q.input :correct, input_html: { class: 'quiz-tab' }, as: :select, collection: [1,2,3,4]
end
end
end
end
end
f.actions
end
end

Unpermitted parameter simple_form

I am trying to create a nested form with Simple_fields in ruby 4.
However, every time i try to enter data into the form I get a unpermitted parameter error in the server console after trying to submit.
I already tried the solutions found in the simple_form wiki and did some testing, but that doesn't seem to work.
The _form:
<%= simple_form_for(#enquiry) do |f| %>
<%= f.error_notification %>
<div class="form-inputs">
<H1>Algemene informatie</H1>
<%= f.input :reference, placeholder: 'Referentie' %>
<br>
<%= f.label :Locatie %>
<%= f.select :location, [['Chemiepark', 'chemiepark'], ['Farmsum', 'farmsum'], ['Winschoten', 'winschoten']] %>
<br>
<%= f.input :description, placeholder: 'Omschrijving' %>
<br>
<%= f.input :date %>
<br>
<%= f.input :amount, placeholder: 'Aantal' %>
</div>
<hr>
<% if false %>
<div class="form-inputs">
<%= f.simple_fields_for :enquiry_measures do |e| %>
<H1>Maatregelen</H1>
<%= e.input :responsible, placeholder: 'Verantwoordelijke' %>
<br>
<%# e.input :needed, as: :check_boxes,
collection: ["ja", "nee"] %>
<% end %>
<br>
</div>
<% end %>
<div class="form-inputs">
<%= f.simple_fields_for :tools do |t| %>
<% #enquiry.tools.each do |tool| %>
<%= field_set_tag 'Tool' do %>
<%= f.simple_fields_for "tool_attributes[]", tool do |tf| %>
<h1>Gereedschappen</h1>
<br>
<%= tf.input :handtool, placeholder: 'Handgereedschap' %>
<% end %>
<% end %>
<% end %>
<% end %>
</div>
<div class="form-actions">
<%= f.button :submit %>
</div>
<% end %>
The strong attributes plus what i tested:
def enquiry_params
# was gegenereerd door de scaffold params.fetch(:enquiry, {})
params.require(:enquiry).permit(:reference, :location, :description, :date, :amount,
:enquiry_measures_attributes => [:done, :responsible, :needed], :tools_attributes => [:handtool] )
#:enquiry_measures_attributes => [:done, :responsible, :needed])
#enquiry_measure_attributes: [:done, :responsible, :needed] )
update
code from models
class Enquiry < ActiveRecord::Base
#ophalen van andere tabellen voor het formulier. Has_many is 1 op veel relatie
#accepts_nested_attributes Nested attributes allow you to save attributes on associated records through the paren
# de dere regel zorgt ervoor dat de maatregelen worden opgehaald via de tussentabel enquiry_measures.
has_many :enquiry_measures, :class_name => 'EnquiryMeasure' #, inverse_of: :Enquiry
accepts_nested_attributes_for :enquiry_measures, :allow_destroy => true
has_many :measures, -> { uniq }, :class_name => 'Measure', :through => :enquiry_measures, dependent: :destroy
accepts_nested_attributes_for :measures, :allow_destroy => false
has_many :controls, :class_name => 'Control' #, inverse_of: :Enquiry
has_many :applicants, :class_name => 'Applicant' #, inverse_of: :Enquiry
has_many :agrees, :class_name => 'Agree' #, inverse_of: :Enquiry
has_many :signatures, :class_name => 'Signature' #, inverse_of: :Enquiry
accepts_nested_attributes_for :signatures, :allow_destroy => false
has_many :tools, :class_name => 'Tool', :dependent => :destroy #, inverse_of: :Enquiry
accepts_nested_attributes_for :tools, :allow_destroy => true
#:dependent => :destroy zorgt ervoor dat de foreign record ook word verwijderd.
#de instances van andere tabellen:
e = Enquiry.new
e.enquiry_measures.build(:enquiry_id => :id)
e.measures.build
# 28-11 MG de pagina's die in het form worden gebruikt.
cattr_accessor :form_steps do
%w(basic when measurements tool)
end
attr_accessor :form_step
validates :reference, presence: true, if: -> { required_for_step?(:basic) }
validates :amount, :date, presence: true, if: -> { required_for_step?(:when) }
#validates :needed, presence: true, if: -> { required_for_step?(:measurements) }
def required_for_step?(step)
return true if form_step.nil?
return true if self.form_steps.index(step.to_s) <= self.form_steps.index(form_step)
end
#voor het mailen met behulp van de mailgem:
# Declare the e-mail headers. It accepts anything the mail method
# in ActionMailer accepts.
def headers
{
:subject => "My Contact Form",
:to => "marco.groenhof#jpbgroep.nl",
:from => %("#{name}" <#{email}>)
}
end
end
and 1 of the related models: in this case enquiry_measure
class EnquiryMeasure < ActiveRecord::Base
belongs_to :enquiry
validates_presence_of :enquiry
has_many :measure
#serialize zodat de data uit de collection select met multiple: true op kan worden geslagen.
serialize :measure
end
and tools:
class Tool < ActiveRecord::Base
belongs_to :enquiry, :class_name => 'Enquiry' #, inverse_of: :applicant
validates_presence_of :enquiry
end
I know class_name is not really needed anymore.
UPDATE
The logging:
Parameters: {"utf8"=>"✓", "authenticity_token"=>"i3YukMoOaYEuUdxk6kmhoQ5q9uLQHHISW+NAU/L+kNjSwMZERmdIIVXZvJUh0vTnEPidaMvMEIlVT/aTlkTNPw==", "enquiry"=>{"reference"=>"Test", "location"=>"chemiepark", "description"=>"3ro0qjhrojeofj", "date(1i)"=>"2017", "date(2i)"=>"1", "date(3i)"=>"3", "amount"=>"2", "tools_attributes"=>{"0"=>{"handtool"=>"Hamer"}}}, "commit"=>"Create Enquiry"}
The only weird thing i see is the "tools_attributes"=>{"0"=>{"handtool"=>"Hamer"}}}
Why is that 0 there? Could it be the id, because that would make sense to why i can not save.
And just to make sure, this is the tool tabel and foreign key:
add_index "tools", ["enquiry_id"], name: "index_tools_on_enquiry_id", using: :btree
create_table "users", force: :cascade do |t|
t.string "name", limit: 255
t.string "email", limit: 255
t.string "password_digest", limit: 255
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
add_foreign_key "tools", "enquiries"
UPDATE 4/01
Just installed rails panel to see what that would say, but i keep thinking the problem is within the parameters:
{"reference":"test","location":"chemiepark","description":"iwopjf","date(1i)":"2017","date(2i)":"1","date(3i)":"4","amount":"2","tools_attributes":{"0":{"handtool":"hamer"}}}
Why does it keep sending that 0? i suspect it to be the tool id, which would declare the not being able to save.
Try making you strong parameter as
params.require(:enquiry).permit(:reference, :location, :description, :date, :amount, enquiry_measures_attributes: [:id, :done, :responsible, :needed, :_destroy], tools_attributes: [:id, :handtool, :_destroy] )
And your model that is being nested should be something as below. Try doing this once.
class Tool < ActiveRecord::Base
# For a while let's not have any validation.
end
Hope this will work in your case as I fix it for my own.
I decided to updatew this question as i got the answer that helped me. It may not be the completely correct answer, but i managed to solve my issue by using the default form_for in uby on Rails. A bit more coding work, but it does work.

Rails enum not saving to database from select options

this is my tables looks like:
class Promo < ActiveRecord::Base {
:id => :integer,
:product_id => :integer,
:promo_code => :string,
:name => :string,
:description => :text,
:user_id => :string,
:email => :string,
:status => :integer,
:category => :integer,
:expire_date => :date,
:user_limit => :integer,
:created_at => :datetime,
:updated_at => :datetime
}
ane here is my model:
class Promo < ActiveRecord::Base
enum category: [ :discount, :rebate, :custom]
enum status: [ :offered, :claimed, :redeemed ]
end
and my view:
<%= f.select :category, options_for_select(Promo.categories.map { |w| w }, #promo.category) %>
which will generate html like this:
<select name="promo[category]" id="promo_category">
<option value="0">discount</option>
<option value="1">rebate</option>
<option value="2">custom</option>
</select>
But when I try to save it, it throw an error which says:
'0' is not a valid category
How to save enum to database? thanks
UPDATE
I have found the link before.
I change it my view like this:
<%= f.select :category, options_for_select(Promo.categories.keys.to_a.map { |w| [w.humanize, w] }, #promo.category) %>
but back to my root problems, its not working, it says that :
ActiveRecord::RecordNotSaved: Failed to save the record
from /home/krismp/.rvm/gems/ruby-2.1.5/gems/activerecord-4.2.3/lib/active_record/persistence.rb:142:in `save!'
why this is happen?
The value submitted by this form snippet won’t validate because update is expecting the “string” key, and not the underlying numerical value of the table.
Instead, you can use following:
<%= f.select :category, options_for_select(Promo.categories.map {|k,v| [k,k]}) %>
or
<%= f.select :category, options_for_select(Promo.categories.map {|k,v| [k,k]}, #promo.category) %>

Rails nested form with has_many :through, not saving the data to joining table

I am kinda new to Rails and this is my first post to StackOverflow.
Say I have 3 models:
class Product < ActiveRecord::Base
default_scope :order => :title
has_many :line_items
has_many :promo_products
has_many :promotions, :through => :promo_products, :foreign_key => :promotion_id
before_destroy :ensure_not_referenced_by_any_line_item
before_destroy :ensure_not_referenced_by_any_promo_product
validates :title, :presence => true, :uniqueness => true
validates :description, :presence => true
validates :price, :numericality => {:greater_than_or_equal_to => 0.01}
private
def ensure_not_referenced_by_any_line_item
if line_items.empty?
return true
else
errors.add(:base, 'Line Items present')
return false
end
end
def ensure_not_referenced_by_any_promo_product
if promo_products.empty?
return true
else
errors.add(:base, 'Some promotions are still in effect')
return false
end
end
end
class Promotion < ActiveRecord::Base
CART_OR_PRODUCT = ['Cart', 'Product']
PROMOTION_TYPE = ['Percentage based', 'Value based']
has_many :promo_products
accepts_nested_attributes_for :promo_products
has_many :products, :through => :promo_products, :foreign_key => :product_id
accepts_nested_attributes_for :products
#attr_accessible :promo_products_attributes, :title, :description, :cart_or_product, :promotion_type, :discount, :minimum_price, :minimum_quantity
validates :title, :description, :presence => true
validates :cart_or_product, :inclusion => {:in => CART_OR_PRODUCT, :message =>
"is invlaid. Please select a valid option"}
validates :promotion_type, :inclusion => {:in => PROMOTION_TYPE, :message =>
"is invalid. Please select a valid option"}
validates :discount, :minimum_price, :numericality => {:greater_than_or_equal_to => 0.00}
validates :minimum_quantity, :numericality => {:greater_than_or_equal_to => 0}
end
class PromoProduct < ActiveRecord::Base
belongs_to :promotion
belongs_to :product
accepts_nested_attributes_for :products
end
In the promotions new page, I would like to show list of products that could be part of a promotion. A user may select 0, 1 or more products, depending on the type of promotion.
In the action new of promotions_controller, I built like this:
#promotion.promo_products.build.build_product
In the _form of promotions, I needed to show the list of products for user to select. I made a nested form like:
<%= form_for(#promotion) do |f| %>
<!-- other promotion fields -->
<%= f.fields_for :promo_products do |pp| %>
<%= pp.fields_for :products do |p| %>
<div class="field">
<%= f.label "Products" %><br />
<%= collection_select :promo_product, :product_id, Product.all, :id, :title {:selected => #promotion.product_ids}, {:multiple => true} %>
</div>
<% end %>
<% end %>
<% end %>
I have 2 issues.
First my code throws an error:
ArgumentError in PromotionsController#new
No association found for name `products'. Has it been defined yet?
If I change the line in PromoProduct model:
accepts_nested_attributes_for :products
to
accepts_nested_attributes_for :product
Then there are no errors, and everything works fine.
The data doesn't get saved to promo_product table. I have the create action in promo_product controller as:
def create
#promotion = current_promotion
products = Product.select(:id => params[:product_id])
products.each do |p|
promo_product = #promotion.promo_products.build(p)
promo_product.save
end
##promo_product = PromoProduct.new(params[:promo_product])
redirect_to promotions_path
end
How can I go about it?
Thank you.
You shouldn't put the "accept_nested_attribute_for" in the association table PromoProducts. It should exist in the model that you want to use for creating association to another model. "accept_nested_attribute_for" IIRC simply inserts an "[association]_attributes=" method for your model. For instance, if you add this method to your Product class for Promotion, you will get "promotion_attributes=" method inserted in the Product class. Then a nested form can use this function to create new objects with a hash that represents the model and association.
Base on the above, the create action shouldn't be in PromoProduct controller, instead it should be in Promotion controller.
<%= form_for(#promotion) do |f| %>
<!-- other promotion fields -->
<%= f.fields_for :products do |pp| %>
<div class="field">
<%= f.label "Products" %><br />
<%= collection_select :promo_product, :product_id, Product.all, :id, :title {:selected => #promotion.product_ids}, {:multiple => true} %>
</div>
<% end %>
<% end %>
I don't know without trying if the above collection_select line is correct. But you can debug this by checking the parameter returned by the form to the controller in the server console log. Basically you should see a nested hash of
{:promotion => {:products => ...}}
Let me know if you need more help on this. In my solution I used a combination of select_tag and options_from_collection_for_select. (But I don't recall the behavior of all these offhand without looking at the API doc.)
Lastly, do you need the :through model? I think since you created the through model you need to handle saving that in your create action. But since you don't have other attributes on the PromoProducts table I wonder if you want to simply leave it as a HABTM association and let rails deal with the rest?

Select multiple facets or filter data simultaneously

UPDATED 6/29/12
I have managed to set up a search and a side bar for filtering results of a search using Sunspot and act-as-taggable with Rails. I was following this tutorial here
but I still can't select mutliple filter's at once. When I select a filter the other sub-category names still disappear. What am I missing?
My Original Question was this:
I'm not quite sure how to select multiple facets at once filtering the
data. So I have multiple sub categories i.e.(hiking, skiing, climbing,
etc.) I want to be able to select hiking and climbing simultaneously
so the data shown is only those objects of hiking and climbing. Right
now I select one (let's say hiking) and all the other options
disappear. Can someone explain?
Below is my code:
Gear Controller
def index
#search = Gear.solr_search do
exclusions = []
fulltext params[:search]
exclusions << with(:sub_category_name, params[:name]) if params[:name].present?
exclusions.compact!
exclusions = nil if exclusions.empty?
facet :sub_category_name
facet :sub_category_name, :exclude => exclusions, :name => :all_categories
paginate(page: params[:page], :per_page => 15)
end
#gears = #search.results
end
** Gear Index View**
<div class="gears_container">
<div class="side_bar_search">
<%= form_tag gears_path, :method => :get do %>
<p>
<%= text_field_tag :keywords, params[:keywords] , class: 'gearsearchbar' %> <%= submit_tag "Search", :name => nil, class: 'btn btn-inverse gearsearchbutton' %>
</p>
<% end %>
<div class="sidebar_section">Sub Category</div>
<ul>
<% for row in #search.facet(:all_categories).rows %>
<li class="sidebar_options">
<% if params[:name].present? %>
<strong><%= row.value %></strong>(<%= link_to "remove", :name => nil %>)
<% else %>
<%= link_to row.value, :name => row.value %> (<%= row.count %>)
<% end %>
</li>
<% end %>
</ul>
</div>
<div c
<div class="search_results_gear">
<% #hits.each do |gear| %>
<%= render partial: 'gear', locals: {gear: gear} %>
<% end %>
<div style="clear:both"></div>
<%= will_paginate #hits, class: 'flickr_pagination' %>
</br>
</div>
</div>
Gear Model
class Gear < ActiveRecord::Base
attr_accessible :title, :size, :price, :sub_category_id, :user_id, :image, :image_a, :remote_image_url, :color, :year, :latefee, :cancellation, :minrental, :policy, :about, :address, :city, :state, :zip, :sub_category_name
belongs_to :user
belongs_to :sub_category
has_one :category, :through => :sub_category
has_many :comments, :dependent => :destroy
has_many :line_items
require 'carrierwave/orm/activerecord'
mount_uploader :image, GearpicUploader
mount_uploader :image_a, GearpicUploader
before_destroy :ensure_not_referenced_by_any_line_item
acts_as_taggable_on :tags
validates :title, presence: true
validates :size, presence: true
validates :price, presence: true
validates :sub_category_id, presence: true
validates :user_id, presence: true
searchable do
text :title, :size, :price, :year, :zip, :state, :city, :minrental, :about, :latefee, :color
text :user_firstname do
user.firstname
end
text :user_lastname do
user.lastname
end
# **Facet Section**
string :size, :price, :year, :zip, :state, :city, :minrental, :latefee, :color
string :sub_category_name , :multiple => true, :stored => true do
sub_category.name
end
string :category_name do
category.name
end
end
private
def ensure_not_referenced_by_any_line_item
if line_items.empty?
return true
else
errors.add(:base, 'Line Items present')
return false
end
end
end
It looks like you need to take advantage of the :exclude option for your faceted search.
def index
#search = Gear.search do
exclusions = []
# tags, AND'd
if params[:tag].present?
all_of do
params[:tag].each do |tag|
exclusions << with(:sub_category_name, tag)
end
end
end
exclusions.compact!
exclusions = nil if exclusions.empty?
facet :sub_category_name
facet :sub_category_name, :exclude => exclusions, :name => :all_categories
paginate(page: params[:page])
end
#hits = #search.results
end
So what I've done above, is create an exclusions array to hold the collection of filters. The with() method returns a filter object, so we capture all the filters in the exclusions array. We do the compact! to remove nil objects from the array, and if it's empty, we make it nil (this is due to the limitations of the :exclude option, if you pass it an empty array, it will not work correctly). We then facet on the same :sub_category_name term, excluding the filters, and also give it a name. This facet will give you all the facet categories excluding the selected ones.
Then in your view, when you display the facet options, you use the named :all_categories facet.
#search.facet(:all_categories).rows.each_with_index do |facet, index|
# This just outputs all the facets, you can add the logic in.
<li><%= facet.value %> (<%= facet.count %>)</li>
end

Resources