Hi. I have a form in my app which, for some reason is not saving any objects to the database. After clicking submit it redirects back to itself, but it dosent give any information as to what is going wrong. Here is the info from development.log, Processing AuctionsController#create (for 127.0.0.1 at 2008-03-25 18:01:56) [POST] Session ID: cbfe7affee5e55448c284a1e488f7b17 Parameters: {"commit"=>"Create", "action"=>"create", "controller"=>"auctions", "auction"=>{"price"=>"5", "title"=>"test title", "category_id"=>"2", "description"=>"test description", "user_id"=>"1", "uploaded_picture"=>#<ActionController::UploadedStringIO:0x51bbd18>}} [4;35;1mCategory Load (0.001000) [0m [0mSELECT * FROM categories [0m Rendering template within layouts/orangeblue Rendering auctions/new Rendered shared/_search (0.00300) Rendered shared/_menubar (0.00300) Rendered shared/_loginside (0.00200) Rendered shared/_itemsuwatchside (0.00200) Completed in 0.07300 (13 reqs/sec) | Rendering: 0.02800 (38%) | DB: 0.00100 (1%) | 200 OK [http://localhost/auctions] Any help would be appreciated, thanks. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Dan Smith wrote:> Hi. I have a form in my app which, for some reason is not saving any > objects to the database. After clicking submit it redirects back to > itself, but it dosent give any information as to what is going wrong. > >We would need to see the code for your ''create'' action in your auctions_controller.rb -- http://www.5valleys.com/ http://www.workingwithrails.com/person/8078 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Auction controller: def create @cats = Category.find(:all) params[:auction][:user_id] = current_user.id @auction = Auction.new(params[:auction]) respond_to do |format| if @auction.save flash[:notice] = ''Auction was successfully created.'' format.html { redirect_to(@auction) } format.xml { render :xml => @auction, :status => :created, :location => @auction } else format.html { render :action => "new" } format.xml { render :xml => @auction.errors, :status => :unprocessable_entity } end end end I also have an items controller, with a create action which is pretty much identical, but works just fine. Item controller: def create @cats = Category.find(:all) params[:item][:user_id] = current_user.id @item = Item.new(params[:item]) respond_to do |format| if @item.save flash[:notice] = ''Item was successfully created.'' format.html { redirect_to(@item) } format.xml { render :xml => @item, :status => :created, :location => @item } else format.html { render :action => "new" } format.xml { render :xml => @item.errors, :status => :unprocessable_entity } end end end -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Dan Smith wrote:> Auction controller: > > def create > @cats = Category.find(:all) > params[:auction][:user_id] = current_user.id > @auction = Auction.new(params[:auction]) > > respond_to do |format| > if @auction.save > flash[:notice] = ''Auction was successfully created.'' > format.html { redirect_to(@auction) } > format.xml { render :xml => @auction, :status => :created, > :location => @auction } > else > format.html { render :action => "new" } > format.xml { render :xml => @auction.errors, :status => > :unprocessable_entity } > end > end > end > > I also have an items controller, with a create action which is pretty > much identical, but works just fine. > > Item controller: > > def create > @cats = Category.find(:all) > params[:item][:user_id] = current_user.id > @item = Item.new(params[:item]) > > respond_to do |format| > if @item.save > flash[:notice] = ''Item was successfully created.'' > format.html { redirect_to(@item) } > format.xml { render :xml => @item, :status => :created, > :location => @item } > else > format.html { render :action => "new" } > format.xml { render :xml => @item.errors, :status => > :unprocessable_entity } > end > end > end >Everything looks good there. You said it''s redirecting back on itself. I assume you mean that it''s going back to the ''new'' action, which is what you have it doing if the save fails (which is good). So, make sure you have the following in your new.html.erb file... <%= error_messages_for :auction %> That should hopefully give you a hint why the save is failing. Probably some validations you have setup that aren''t passing. -- http://www.5valleys.com/ http://www.workingwithrails.com/person/8078 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---