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 %>
<p>User Name : <%= text_field 'user', 'name' %></p>
<p>Password : <%= password_field 'user', 'password' %></p>
<%= submit_tag "Create New User"%>
<% end %>

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 Cohen wrote:

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

Thanx Shandy........... :slight_smile:

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?

#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

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

Fred

You are right. I forgot about my validations.

Thanks for pointer on city.errors