Topic: don't understand form_for

I'm trying to create a form that will simply contain a select.

The user logs in and then goes to a page to select from a list of groups that they previously created.  The user is associated with groups through a has_many relationship.  So I find the user by user_id.

Then I want to cycle through the group names associated with that user to display in the select.

to get the groups, I do

@groupnames = @user.groups.find(:all)

in the controller

Then on the form page I try

<%  form_for :group, :url => {:action => :send} do |form| %>

  <%= form.collection_select( :name, @groupnames, :id, :name) %>
  <%= submit_tag "Select" %>
<% end %>

based on what I've read this seems to be the right way to do it.

But not matter what I do (even if I just try to put in a text field) and take out the select box, I get this error:

ArgumentError in ResultsController#index

wrong number of arguments (1 for 0)

RAILS_ROOT: G:/radrailsworkspace/salarysurveyp2/config/..

I'm thinking that I don't really understand how to use the form_for tag. Any help is appreciated.

Re: don't understand form_for

Looks like you are doing it correctly. Can you post the full error message with the stack trace?

BTW, you can do this for selecting all the groups, no need to do find(:all)

@groupnames = @user.groups

Railscasts - Free Ruby on Rails Screencasts

Re: don't understand form_for

I ended up just deleting everything from the controller and adding it back in one piece at a time once I couldn't figure out what was wrong with the way I was doing the form.

I had

def send

and once I took that out, the error resolved itself.  I have no idea why.  Is "send" some sort of already defined function?

Thanks for the advice, btw.  So @user.groups will just automatically give me the groups associated with that user?

Re: don't understand form_for

send is a reserved method of the Object class in Ruby:

class Dog    
    def bark(noise)
      puts noise
dog =
dog.send :bark, "woof!"

# outputs "woof!" … bject.send

Re: don't understand form_for

got it.  Thanks for the info.