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:increate’

/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:inperform_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:inperform_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:inmeasure’
/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:inperform_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:inprocess_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:inprocess’
/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:indispatch’
/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:insynchronize’
/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:inprocess_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:inprocess_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:ininitialize’
/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:inrun’
/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:innew’
/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:inrun’
/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:inrun’
/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:inrun’
/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:increate’
/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:inperform_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:inperform_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:inmeasure’
/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:inperform_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:inprocess_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:inprocess’
/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:indispatch’
/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:insynchronize’
/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:inprocess_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:inprocess_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:ininitialize’
/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:inrun’
/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:innew’
/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:inrun’
/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:inrun’
/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:inrun’
/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


:user: 1
:return_to:
flash: !map:ActionController::Flash::FlashHash
:notice: Mitgliedschaft

Response
Headers: {“cookie”=>[], “Cache-Control”=>“no-cache”}

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!

Michelle

Pascal F. wrote:

To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~–~—


View this message in context:
http://old.nabble.com/To-few-arguments-exception---redirect-after-many-to-many-association-creation-tp13547725p29838288.html
Sent from the RubyOnRails Users mailing list archive at Nabble.com.

10 years later and I am making the same mistake. Glad I didn’t waste my own 2 hours on this.