Issues doing an insert into mysql

Everything looks ok, I can not see errors, I do not see anything in the table.

This is my environment settings.

Ruby version 1.8.6 (i386-linux) RubyGems version 1.3.7 Rack version 1.0 Rails version 2.3.4 Active Record version 2.3.4 Active Resource version 2.3.4 Action Mailer version 2.3.4 Active Support version 2.3.4 Application root /home/stud/fun_facts Environment development Database adapter mysql Database schema version 20101120032325

Out put from server:

=> Booting Mongrel => Rails 2.3.4 application starting on http://0.0.0.0:3000 => Call with -d to detach => Ctrl-C to shutdown server   SQL (309.9ms) SET NAMES 'utf8'   SQL (0.4ms) SET SQL_AUTO_IS_NULL=0

Processing FactController#add (for 127.0.0.1 at 2010-12-21 13:45:06) [GET]   Fact Columns (714.5ms) SHOW FIELDS FROM `facts`   SQL (3.3ms) BEGIN   SQL (1.5ms) ROLLBACK Rendering fact/add

Processing FactController#add (for 127.0.0.1 at 2010-12-21 13:45:50) [POST]   Parameters: {"commit"=>"Add Fact", "authenticity_token"=>"O9D0iM9ouiEZdU+98pkDh6BGunEltXuaoUNTVU2ezRs=", "fact"=>{"fact"=>"This is a fun fact 4.", "screen_name"=>"Denter", "email"=>"Denter@email.com"}}   Fact Columns (3.5ms) SHOW FIELDS FROM `facts`   SQL (0.2ms) BEGIN   SQL (0.3ms) ROLLBACK Rendering fact/add

I am not sure why we are getting the rollback.

The debug setting on the page show that I am submitting the data.

--- !map:HashWithIndifferentAccess commit: Add Fact authenticity_token: O9D0iM9ouiEZdU+98pkDh6BGunEltXuaoUNTVU2ezRs= action: add fact: !map:HashWithIndifferentAccess   fact: This is a fun fact 4.   screen_name: Denter   email: Denter@email.com controller: fact

I am not sure what is going wrong.

My controller .

class FactController < ApplicationController   def index      @title = "Index"   end

  def add      @title = "Add Facts"

    @fact = Fact.new(params[:screen_name])

      respond_to do |format|       if @fact.save         format.html {flash[:notice] = 'Fact was successfully added.', redirect_to(@fact) }         format.xml { render :xml => @fact, :status => :created, :location => @fact }       else         format.html { render :action => "add" }         format.xml { render :xml => @fact.errors, :status => :unprocessable_entity }       end     end   end

end

Thanks for the help!

Everything looks ok, I can not see errors, I do not see anything in the table.

This is my environment settings.

Ruby version 1.8.6 (i386-linux) RubyGems version 1.3.7 Rack version 1.0 Rails version 2.3.4 Active Record version 2.3.4 Active Resource version 2.3.4 Action Mailer version 2.3.4 Active Support version 2.3.4 Application root /home/stud/fun_facts Environment development Database adapter mysql Database schema version 20101120032325

Out put from server:

=> Booting Mongrel => Rails 2.3.4 application starting on http://0.0.0.0:3000 => Call with -d to detach => Ctrl-C to shutdown server SQL (309.9ms) SET NAMES 'utf8' SQL (0.4ms) SET SQL_AUTO_IS_NULL=0

Processing FactController#add (for 127.0.0.1 at 2010-12-21 13:45:06) [GET] Fact Columns (714.5ms) SHOW FIELDS FROM `facts` SQL (3.3ms) BEGIN SQL (1.5ms) ROLLBACK Rendering fact/add

Processing FactController#add (for 127.0.0.1 at 2010-12-21 13:45:50) [POST] Parameters: {"commit"=>"Add Fact", "authenticity_token"=>"O9D0iM9ouiEZdU+98pkDh6BGunEltXuaoUNTVU2ezRs=", "fact"=>{"fact"=>"This is a fun fact 4.", "screen_name"=>"Denter", "email"=>"Denter@email.com"}} Fact Columns (3.5ms) SHOW FIELDS FROM `facts` SQL (0.2ms) BEGIN SQL (0.3ms) ROLLBACK Rendering fact/add

I am not sure why we are getting the rollback.

The debug setting on the page show that I am submitting the data.

--- !map:HashWithIndifferentAccess commit: Add Fact authenticity_token: O9D0iM9ouiEZdU+98pkDh6BGunEltXuaoUNTVU2ezRs= action: add fact: !map:HashWithIndifferentAccess fact: This is a fun fact 4. screen_name: Denter email: Denter@email.com controller: fact

I am not sure what is going wrong.

My controller .

class FactController < ApplicationController def index     @title = "Index" end

def add     @title = "Add Facts"

    @fact = Fact.new(params[:screen_name])

params[:screen_name] doesn't exist. I think you want params[:fact]

screen_name is one of the parameters

Parameters: {“commit”=>“Add Fact”, “authenticity_token”=>"

O9D0iM9ouiEZdU+98pkDh6BGunEltXuaoUNTVU2ezRs=",

“fact”=>{“fact”=>“This is a fun fact 4.”, “screen_name”=>“Denter”, “email”=>“Denter@email.com”}}

Fact Columns (3.5ms) SHOW FIELDS FROM facts

SQL (0.2ms) BEGIN

SQL (0.3ms) ROLLBACK

Rendering fact/add

I am not sure why I get the rollback.

screen_name is one of the parameters

Yes, but it’s part of the fact hash…

params[:screen_name] => nil

params[:fact][:screen_name] => Denter

As Philip's already pointed out, you're not grabbing the incoming data from the right element of params. In addition, the rollback is a sign that something is failing validation - can you post your model code?

--Matt Jones

Thanks!