Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3843780
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T15:59:12+00:00 2026-05-19T15:59:12+00:00

I am trying to learn rails from zero programming experience and have an app

  • 0

I am trying to learn rails from zero programming experience and have an app im trying to make. With much help from people on here, I have an index page of venues which are filterable by which area they belong to via a dropdown menu. I would like to be able to have the same affect but using checkboxes and also being able to select multiple areas to add to the filter. This is what I have so far:

Model :

class Venue < ActiveRecord::Base
  belongs_to :user
  has_many :reviews
  belongs_to :area

  scope :north, where(:area_id => "2")
  scope :west, where(:area_id => "3")
  scope :south, where(:area_id => "4")
end

Controller:

def index
  if (params[:area] && Area.all.collect(&:name).include?(params[:area][:name]))
    @venues = Venue.send(params[:area][:name].downcase)
  else
    @venues = Venue.all
  end
end

Venues index.html.erb:

<div class="filter_options_container">

  <form class="filter_form", method="get">
    <%= select("area", "name", Area.all.collect(&:name), {:prompt => 'All Areas'}) %><br>
    <input type="submit" value="Filter" />
  </form>

  <br><br>

  <form class="filter_form", method="get">
    <% Area.find(:all).each do |a| %>
      <%= check_box_tag("area", "name") %>
      <%= a.name %>
    <% end %>
    <input type="submit" value="Filter" />
  </form>
</div>

<div class="venue_partials_container">
  <%= render :partial => 'venue', :collection => @venues %>
  <div class="clearall"></div>
  <%= link_to 'add a new venue', new_venue_path, :class => "add_new_venue_button" %>
</div>

The first form (the dropdowns) in the filter_options_container works fine but the checkboxes (the second form) is returning “can’t convert Symbol into Integer” what am I missing/doing wrong?

Thankyou for any help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T15:59:13+00:00Added an answer on May 19, 2026 at 3:59 pm

    I don’t know exactly what’s causing your error, but I can tell you that the check_box_tag helper isn’t working the way you expect it to. From the documentation, it’s defined like this:

    check_box_tag(name, value = "1", checked = false, options = {})
    

    So calling check_box_tag("area", "name") repeatedly will just give you <input id="area" name="area" type="checkbox" value="name" /> multiple times. Note that the “value” attribute (which is the value that gets sent to your server when that form is submitted) is always “name” – not what you want!

    Instead, try the following:

    <% Area.all.each do |a| %>
        <%= check_box_tag("areas[]", a.id) %>
        <%=h a.name %>
    <% end %>
    

    The things I’ve changed:

    1. I used Area.all instead of Area.find(:all) – I did it for cosmetic reasons, but DanneManne’s answer claims it’s obsolete in Rails 3 (I wouldn’t know – I’m still on 2.3.8).
    2. I used the area’s ID instead of its name in the value field; it’s always good to look things up by ID if you can – IDs are integers, and compare faster than strings, and there’ll always be an index on the id column in your database for extra-fast lookups.
    3. And last, but way most importantly I threw in [] after the input name. This lets Rails collect all the values submitted with this name into an array, rather than just taking the last one. See below:

    Throwing the URL…

    /whatever?a=3&a=17&a=12
    

    …at a Rails app gives you the params hash…

    {:a => 12}
    

    …but the URL…

    /whatever?a[]=3&a[]=17&a[]=12
    

    …gives you what you want:

    {:a => [3, 17, 12]}
    

    And if you have an array of all the area_ids you’re interested in, you can get all the venues that are in any of those areas in a one-liner (isn’t Rails great?):

    filtered_venues = Venue.all(:conditions => {:area_id => params[:areas]})
    

    Just make sure you have a valid array of area ids before calling that finder – if you don’t, your conditions hash will evaluate to {:area_id => nil}, and Rails’ll find you all the venues that don’t have an area_id – probably none, and definitely not what you want.

    Hope this helps!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to install the new Rails 3 release on OSX 10.6. Have never touched
I'm trying to learn some Rails but I seem to get stuck on this
I am trying to learn how to write plugins in Rails by learning other
I'm trying to learn some basics of Ruby on Rails and encountered a problem
I've been following the rails edge guide in building a simple recipe app, and
I have started to do some programming using VIM. I have very mixed feelings
I am trying to install LESS in a Ruby on Rails project. I am
Still trying to learn the basic of jquery so in the weekend I started
So I'm getting started learning Rails. Now that Rails 3 is out, I want
I'm an experienced C/C++/C#/Objective-C desktop,web, and mobile programmer and I've become accustomed to building

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.