How to save data in database

hi i m new to ROR…I want to save my data in my table…

i created form like this…

<% form_tag :action => “create” do %>

User Name : <%= text_field 'user', 'name' %>

Password : <%= password_field 'user', 'password' %>

<%= submit_tag "Create New User"%> <% end %> ---------------------------------------------------------------- and in usercontroller .............

def new
@user = User.new
end

def create
@user = User.new(params[:user])
if @user.save
redirect_to :action => ‘list’
else
redirect_to :action => ‘new’
end
end

there is no error but my data is not saved???
help me

On Apr 25, 2:26 pm, Manish N. [email protected]
wrote:

and in usercontroller …
redirect_to :action => ‘new’
end
end

there is no error but my data is not saved???
help me

Posted viahttp://www.ruby-forum.com/.

Did you check your log files?

If you’re on Rails 2.0 and following general RESTful design, this
series might help: http://softiesonrails.com/search?q=forms+in+rails

Jeff
softiesonrails.com

Jeff C. wrote:

On Apr 25, 2:26�pm, Manish N. [email protected]
wrote:

and in usercontroller …
� � � � � � redirect_to :action => ‘new’
� � � end
� end

there is no error but my data is not saved???
help me

Posted viahttp://www.ruby-forum.com/.

Did you check your log files?

If you’re on Rails 2.0 and following general RESTful design, this
series might help: http://softiesonrails.com/search?q=forms+in+rails

Jeff
softiesonrails.com

I m new…
so wht should i check in log files…???

Thanx Shandy… :slight_smile:

I m new…
so wht should i check in log files…???

When you call your create method in your user_controller look to see if
there are any errors being thrown when you say @user.save. Where does
your page redirect to when you try and save the user information? It
looks like to me that if your save goes bad than you will be redirected
to the “new” page. Is that what it is doing?

Usually any errors in your log file will be noticable - they will be
long and print out a trace stack of where the error occured.

Good luck,

-Shandy

I think I have a more simplified (fundamental) question on this subject.

I went to the irb using ‘script/console’ in my rails app.

I created a new record by typing the following:

city = City.new #City is the name of my class I recently created

city.name = ‘Murray’

city.population = 78000

#I’ve omitted the irb responses

#everything looks fine when I ask

city #it returns the values assigned to the table columns ‘name’ and ‘population’

#My problem is when I type

city.save #it returns false when I expected true!

#at first, I thought it may be because I need to su in as root to save
the changes, but not the case. I am using Suse 10.3, Rails 2.0, and
mysql 5.0

any ideas?

You are right. I forgot about my validations.

Thanks for pointer on city.errors

On 23 May 2008, at 13:07, Jason L. wrote:

city.save #it returns false when I expected true!

#at first, I thought it may be because I need to su in as root to save
the changes, but not the case. I am using Suse 10.3, Rails 2.0, and
mysql 5.0

you’ve probaly got some validations preventing saving. After city.save
has returned false, check city.errors

Fred