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 %>
----------------------------------------------------------------
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 25.04.2008 21:26
on 25.04.2008 21:37
On Apr 25, 2:26 pm, Manish Nautiyal <rails-mailing-l...@andreas-s.net> 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
on 25.04.2008 21:48
Jeff Cohen wrote: > On Apr 25, 2:26�pm, Manish Nautiyal <rails-mailing-l...@andreas-s.net> > 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........?????
on 25.04.2008 23:14
> > 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
on 26.04.2008 07:18
Thanx Shandy........... :)
on 23.05.2008 14:07
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?
on 23.05.2008 15:21
On 23 May 2008, at 13:07, Jason Lillywhite 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
on 23.05.2008 21:52
You are right. I forgot about my validations. Thanks for pointer on city.errors