To few arguments exception - redirect after many to many association creation

Hi there,

i get an error i -really- don't understand.
i have 3 models, project, user and membership.
a user is a member of many projects through memberships and projects
have many members through memberships.

here some snippets:

class Project < ActiveRecord::Base
  has_many :members, :through => :memberships, :source
=> :user, :conditions => "is_manager = false"
  has_many :memberships
end

class User < ActiveRecord::Base
  has_many :memberships
  has_many :projects, :through => :memberships
end

class Membership < ActiveRecord::Base
  belongs_to :user
  belongs_to :project
end

iam -trying- to develop the app restfull. The only actions my
membership controller knows
are the new and create action. After creating the association i want
to redirect to the
project used in the association:

class MembershipController < ApplicationController

  def new
    .... some stuff here
  end

  def create
    @membership = Membership.new(params[:membership])
    if @membership.save
        flash[:notice] = 'Membership of #{@membership.user.name} in
#{@membership.project.name} created.'
        format.html { redirect_to project_url(@membership.project) }
        format.xml { head :created, :location =>
project_url(@membership.project) }
      else
        format.html { render :action => "new" }
        format.xml { render :xml => @membership.errors.to_xml }
      end
  end

end

after hitting the submit button in the new form the membership is
successfully created
but the redirect to the project index doesn't work. even a
redirect_to('/') or a
redirect_to :controller => 'home' raises the same exception...

i am stuck since a few hours...

pascal

oh and of course the error:

too few arguments

RAILS_ROOT: /home/paukul/rails/mopszeise/config/..
Application Trace | Framework Trace | Full Trace

/home/paukul/rails/mopszeise/app/controllers/membership_controller.rb:
12:in `format'
/home/paukul/rails/mopszeise/app/controllers/membership_controller.rb:
12:in `create'

/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.4/lib/action_controller/
base.rb:1101:in `send'
/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.4/lib/action_controller/
base.rb:1101:in `perform_action_without_filters'
/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.4/lib/action_controller/
filters.rb:696:in `call_filters'
/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.4/lib/action_controller/
filters.rb:688:in `perform_action_without_benchmark'
/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.4/lib/action_controller/
benchmarking.rb:66:in `perform_action_without_rescue'
/usr/lib/ruby/1.8/benchmark.rb:293:in `measure'
/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.4/lib/action_controller/
benchmarking.rb:66:in `perform_action_without_rescue'
/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.4/lib/action_controller/
rescue.rb:83:in `perform_action'
/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.4/lib/action_controller/
base.rb:435:in `send'
/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.4/lib/action_controller/
base.rb:435:in `process_without_filters'
/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.4/lib/action_controller/
filters.rb:684:in `process_without_session_management_support'
/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.4/lib/action_controller/
session_management.rb:114:in `process'
/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.4/lib/action_controller/
base.rb:334:in `process'
/usr/lib/ruby/gems/1.8/gems/rails-1.2.4/lib/dispatcher.rb:41:in
`dispatch'
/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/rails.rb:78:in
`process'
/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/rails.rb:76:in
`synchronize'
/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/rails.rb:76:in
`process'
/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:618:in
`process_client'
/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:617:in `each'
/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:617:in
`process_client'
/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:736:in `run'
/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:736:in
`initialize'
/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:736:in `new'
/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:736:in `run'
/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:720:in
`initialize'
/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:720:in `new'
/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:720:in `run'
/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/configurator.rb:
271:in `run'
/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/configurator.rb:
270:in `each'
/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/configurator.rb:
270:in `run'
/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/bin/mongrel_rails:127:in
`run'
/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/command.rb:
211:in `run'
/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/bin/mongrel_rails:243

/home/paukul/rails/mopszeise/app/controllers/membership_controller.rb:
12:in `format'
/home/paukul/rails/mopszeise/app/controllers/membership_controller.rb:
12:in `create'
/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.4/lib/action_controller/
base.rb:1101:in `send'
/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.4/lib/action_controller/
base.rb:1101:in `perform_action_without_filters'
/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.4/lib/action_controller/
filters.rb:696:in `call_filters'
/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.4/lib/action_controller/
filters.rb:688:in `perform_action_without_benchmark'
/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.4/lib/action_controller/
benchmarking.rb:66:in `perform_action_without_rescue'
/usr/lib/ruby/1.8/benchmark.rb:293:in `measure'
/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.4/lib/action_controller/
benchmarking.rb:66:in `perform_action_without_rescue'
/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.4/lib/action_controller/
rescue.rb:83:in `perform_action'
/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.4/lib/action_controller/
base.rb:435:in `send'
/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.4/lib/action_controller/
base.rb:435:in `process_without_filters'
/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.4/lib/action_controller/
filters.rb:684:in `process_without_session_management_support'
/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.4/lib/action_controller/
session_management.rb:114:in `process'
/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.4/lib/action_controller/
base.rb:334:in `process'
/usr/lib/ruby/gems/1.8/gems/rails-1.2.4/lib/dispatcher.rb:41:in
`dispatch'
/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/rails.rb:78:in
`process'
/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/rails.rb:76:in
`synchronize'
/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/rails.rb:76:in
`process'
/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:618:in
`process_client'
/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:617:in `each'
/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:617:in
`process_client'
/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:736:in `run'
/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:736:in
`initialize'
/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:736:in `new'
/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:736:in `run'
/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:720:in
`initialize'
/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:720:in `new'
/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:720:in `run'
/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/configurator.rb:
271:in `run'
/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/configurator.rb:
270:in `each'
/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/configurator.rb:
270:in `run'
/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/bin/mongrel_rails:127:in
`run'
/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/command.rb:
211:in `run'
/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/bin/mongrel_rails:243

Request

Parameters: {"membership"=>{"project_id"=>"5", "is_manager"=>"1",
"user_id"=>"1"}, "commit"=>"Create"}

Show session dump

argh... i was missing the respond_to block around it... 2 hours waste
of time...

So funny! I have been searching since yesterday for a solution to a Can't
create without an ID Create#TitlesController error. Then I discovered a
glitch in how I was authenticating the page. *That* gave me the Too Few
Parameters error and *this* solved it for me. I had commented out the
response_to block by mistake and simply didn't notice it!

I'm glad you posted this as it finally had me looking explicitly at that
block! <big smile>

Michelle

Pascal Friederich wrote: