views:

19

answers:

1

And as a result its not passing validation.

This is my embedded form :

- form_for [@organization, @referral] do |f|
  = f.error_messages

  = render :partial => 'referral_fields', :locals => { :f => f }

  = f.submit "Submit", :class => "button"


#_referral_fields.html.haml

.grid_7
  .grid_1{:style => "width: 64px;"}
    = f.label :org_name, "Business", :class => "right"
  .grid_4
    = f.text_field_tag :org_name
.grid_7
  .grid_1{:style => "width: 64px;"}
    = f.label :name,  '', :class => "right"
  .grid_4
    = f.text_field_tag :name
.grid_7
  .grid_1{:style => "width: 64px;"}
    = f.label :email, '', :class => "right"
  .grid_2.omega{:style => "width: 114px;"}
    = f.text_field_tag :email, '', :style => "width: 125px;"
  .grid_1.alpha
    = f.label :town, '', :class => "right"
  .grid_2
    = f.text_field_tag :town, '', :style => "width: 100px;"

And when I click submit, SQL definately reads the data I inputted :

Processing ReferralsController#create (for ::1 at 2010-10-18 09:39:07) [POST]
  Parameters: {"name"=>"asdfasd", "commit"=>"Submit", "action"=>"create",   "authenticity_token"=>"/1bwOqHjojde3p0Py08mCrko8xULE4R+eXUvT6qf1cE=", "controller"=>"referrals", "org_name"=>"asdfasdf", "organization_id"=>"1", "town"=>"asdfasd", "email"=>"asdfasd"}

Not sure what I'm missing. Here is controllers and models :

#referral.rb
belongs_to :organization, :touch => true
validates_presence_of :org_name, :name, :email, :town  

#referrals_controller.rb

def new
  @referral = Referral.new
  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
+1  A: 

From looking at the parameters, it doesn't look like you have your form fields setup properly?

You are using the params[:referral] hash to build the referral, but I don't see a :referral hash in your parameter list....

Your form fields should look like this:

<input name="referral[name]"/>
<input name="referral[town]"/>
<input name="referral[org_name]"/>

etc...

And then in your parameter list you should be something like { :referral => {:name => "foo", "org_name" => "bar", town => "Boise" } }

Gordon Isnor
ah you're right. i'm probably not passing my locals apprioriately? I updated my form above so you can see the partial. my inputs currently look like this `<input type="text" name="org_name" id="org_name">`
Trip
Looking at the form, I can't say there is anything wrong with it. It has to be the controller somehow.
Trip
use `= f.text_field` and not `= f.text_field_tag`
Yannis
Yannis that worked, wtf? Text_Field_tag deprecated?
Trip
text_field_tag is a FormTagHelper whereas text_field is a FormHelper, two different things. Have a look at the doc (http://railsapi.com/doc/rails-v3.0.0/).
Yannis