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

  • Home
  • SEARCH
  • 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 7089427
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:55:13+00:00 2026-05-28T07:55:13+00:00

I followed the directions in Railscast #17 HABTM Checkboxes (revised) to get this code

  • 0

I followed the directions in Railscast #17 HABTM Checkboxes (revised) to get this code for adding services to a project using a has_and_belongs_to_many association:

<% Service.all.each do |service| %>
     <%= hidden_field_tag "project[service_ids][]", nil %>
     <%= check_box_tag "project[service_ids][]", service.id, @project.service_ids.include?(service.id), id: dom_id(service) %>
     <%= label_tag dom_id(service), service.name %><br />
<% end %>

This works correctly, but I’d like to use Formtastic to generate the code in order to keep the formatting consistent with the rest of the page. The video mentions that Formtastic can do this easily, but I can’t figure out the code for the life of me.

My guess was to do something like this:

<%= semantic_form_for :services do |f| %>
    <%= f.input :name, :as => :check_boxes, :collection => Service.find(:all) %>
<% end %>

and that generates the list of services, but checking the boxes does not do anything. I know that last bit of code need to be linked somehow to the projects_services association, but I don’t know how to do it.

  • 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-28T07:55:14+00:00Added an answer on May 28, 2026 at 7:55 am

    Okay, I was trying to make this harder than it is. This is all I had to do:

    <%= f.input :services, :as => :check_boxes %>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I followed the directions in this post: how can we integrate jquery autocomplete using
I followed the directions on http://source.android.com/source/downloading.html to get the Android source code. Now I
I followed this tutorial: https://github.com/EllisLab/CodeIgniter/wiki/PDF-generation-using-dompdf However, I can't seem to set the path right.
I followed the directions on how to create web applications using Go, and I
I followed the directions in this *link and the while the all sites search
I'm not getting cached results using the ASIHTTPRequest Cache functionality. I followed the directions
I've followed the directions here to build html documentation https://code.ros.org/trac/opencv/browser/trunk/opencv/doc/README.txt (actually my local copy
I'm trying to get a Django app running with Lighttpd. I followed the directions
Followed directions in Using JSLint in Notepad++ . Using JavaScript Lint (not JSLint). I
I've installed the latest CruiseControl and PHPUnderControl, and followed all the directions. I get

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.