views:

35

answers:

0

I am making a self duplicating form. It can create multiple instances of itself.

The hiearchy is, an Organization has_many Referrals.

There should be no 'updating'. It should be only a 'create'.

My error is :

Unknown action

No action responded to update. Actions: create and new

My Form:

- form_for @organization, :url => organization_referrals_path do |f|
  = f.error_messages
  .clear

  = render :partial => 'referral_fields', :locals => {:f => f}
  = link_to_add_fields "Add Another Referral", f, :referrals
  = f.submit "Submit", :class => "button"


#referrals_fields

- fields_for :referral, referral_fields do |qf|
  .grid_7
    .grid_1{:style => "width: 64px;"}
      = qf.label :org_name, "Business", :class => "right"
    .grid_4
      = qf.text_field :org_name
  .grid_7
    .grid_1{:style => "width: 64px;"}
      = qf.label :name, '', {:class => "right"}
    .grid_4
      = qf.text_field :name
  .grid_7
    .grid_1{:style => "width: 64px;"}
      = qf.label :email, '', :class => "right"
    .grid_2.omega{:style => "width: 114px;"}
      = qf.text_field :email, {:style => "width: 125px;"}
    .grid_1.alpha
      = qf.label :town, '', :class => "right"
    .grid_2
      = qf.text_field :town, {:style => "width: 100px;"}

  .clear

#referrals_controller.rb

  before_filter :get_organization
  before_filter :get_any_organization

  def new
    @referral = Referral.new
    2.times { @organization.referrals.build }
    respond_to do |format|
      format.html { render :layout => 'manage' }
    end
  end

  def create
    @referral = Referral.new(params[:referral])
    if @referral.valid? && @organization.referrals << @referral
      flash[:notice] = "Referrals saved."
      redirect_to new_organization_referrals_path(@organization)
    else
      render :action => :new, :layout => 'manage'
    end
  end

Organization.rb

has_many :referrals
accepts_nested_attributes_for :referrals, :reject_if => lambda { |a| a[:content].blank? }, :allow_destroy => true

routes

map.resources :organizations,
            :member => {
                         :referrals => :get

Log

Processing ReferralsController#update (for ::1 at 2010-10-18 15:27:16) [PUT]
Parameters: {"commit"=>"Submit", "action"=>"update", "_method"=>"put",    "authenticity_token"=>"/1bwOqHjojde3p0Py08mCrko8xULE4R+eXUvT6qf1cE=", "controller"=>"referrals", "organization_id"=>"1", "referral"=>{"name"=>"lkjlkj", "org_name"=>"biz 2", "town"=>"lkjlkj", "email"=>"lkjlkj"}}


ActionController::UnknownAction (No action responded to update. Actions: create and new):
  haml (2.2.2) [v] rails/./lib/sass/plugin/rails.rb:19:in `process'

Long Story Short:

All I am trying to do is make a form that has a nested form inside of it, and that nested form can be duplicated. So if an organization has a referral. It can add more referrals if need be. And each referral uses the same form. When the submit button is pressed, all referrals and saved at once.