I think what I'm trying to do is pretty simple, and I'm really not sure why this isn't working. I'm using Rails 3.
Essentially, I'm just trying to select the distinct values from a column in an existing model, and print them out all. For the most part, this works but the .each loop in my view also ends up printing the entire array at the end of the loop. (
I a model called Attractions, and each attraction has a Category (right now the Category is hardcoded in the DB for simplicity).
This is the Attraction Model and a class method "all_categories" defined...
class Attraction < ActiveRecord::Base
class AttractionsController < ApplicationController
@categories = Attraction.all_categories
@attractions = Attraction.find(:all)
@attraction = Attraction.find(params[:id])
<%= @categories.each do |c| %>
<%= c.category %><br/>
<% end %>
[#<Attraction category: "Architecture">, #<Attraction category: "Art">, #<Attraction category: "Fashion">, #<Attraction category: "Music">]
# Change this line with an =: <%= @categories.each do |c| %> # ...to this: <% @categories.each do |c| %>
You only want the side effects on the block of the
#each method, you don't want interpolation of the returned value.