It seems rather odd but my application will happily allow me to add new records via my form, but using the same form partial the edit action seems to work fine (It throws no errors) but completely fails to change the database in any way. Do I need to add a @users.save command or something? Here is my UsersController code class UsersController < ApplicationController # GET /users # GET /users.xml def index if params[:usersearch].blank? @users = User.find(:all) else @users = User.find(:all, :conditions => [''Surname LIKE ? or Forename LIKE ? or Position_Group LIKE ?'', "%#{params[:usersearch]}%", "%#{params[:usersearch]}%", "%#{params[:usersearch]}%"]) end respond_to do |format| format.html # index.html.erb format.xml { render :xml => @users } end end # GET /users/1 # GET /users/1.xml def show @user = User.find(params[:id]) respond_to do |format| format.html # show.html.erb format.xml { render :xml => @user } end end # GET /users/new # GET /users/new.xml def new @user = User.new respond_to do |format| format.html # new.html.erb format.xml { render :xml => @user } end end # GET /users/1/edit def edit @user = User.find(params[:id]) end # POST /users # POST /users.xml def create @user = User.new(params[:user]) respond_to do |format| if @user.save flash[:notice] = ''User was successfully created.'' format.html { redirect_to(@user) } format.xml { render :xml => @user, :status => :created, :location => @user } else format.html { render :action => "new" } format.xml { render :xml => @user.errors, :status => :unprocessable_entity } end end end # PUT /users/1 # PUT /users/1.xml def update @user = User.find(params[:id]) respond_to do |format| if @user.update_attributes(params[:user]) flash[:notice] = ''User was successfully updated.'' format.html { redirect_to(@user) } format.xml { head :ok } else format.html { render :action => "edit" } format.xml { render :xml => @user.errors, :status => :unprocessable_entity } end end end # DELETE /users/1 # DELETE /users/1.xml def destroy @user = User.find(params[:id]) @user.destroy respond_to do |format| format.html { redirect_to(users_url) } format.xml { head :ok } 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 -~----------~----~----~----~------~----~------~--~---
What does the form partial look like? On Jun 4, 2008, at 6:57 AM, Dale Cunnigham wrote:> > It seems rather odd but my application will happily allow me to add > new > records via my form, but using the same form partial the edit action > seems to work fine (It throws no errors) but completely fails to > change > the database in any way. Do I need to add a @users.save command or > something? > > Here is my UsersController code > > class UsersController < ApplicationController > # GET /users > # GET /users.xml > def index > if params[:usersearch].blank? > @users = User.find(:all) > else > > @users = User.find(:all, :conditions => [''Surname LIKE ? or > Forename LIKE ? or Position_Group LIKE ?'', "%#{params[:usersearch]}%", > "%#{params[:usersearch]}%", "%#{params[:usersearch]}%"]) > end > > respond_to do |format| > format.html # index.html.erb > format.xml { render :xml => @users } > end > end > > # GET /users/1 > # GET /users/1.xml > def show > @user = User.find(params[:id]) > > respond_to do |format| > format.html # show.html.erb > format.xml { render :xml => @user } > end > end > > # GET /users/new > # GET /users/new.xml > def new > @user = User.new > > respond_to do |format| > format.html # new.html.erb > format.xml { render :xml => @user } > end > end > > # GET /users/1/edit > def edit > @user = User.find(params[:id]) > end > > # POST /users > # POST /users.xml > def create > @user = User.new(params[:user]) > > respond_to do |format| > if @user.save > flash[:notice] = ''User was successfully created.'' > format.html { redirect_to(@user) } > format.xml { render :xml => @user, :status => :created, > :location => @user } > else > format.html { render :action => "new" } > format.xml { render :xml => @user.errors, :status => > :unprocessable_entity } > end > end > end > > # PUT /users/1 > # PUT /users/1.xml > def update > @user = User.find(params[:id]) > > respond_to do |format| > if @user.update_attributes(params[:user]) > flash[:notice] = ''User was successfully updated.'' > format.html { redirect_to(@user) } > format.xml { head :ok } > else > format.html { render :action => "edit" } > format.xml { render :xml => @user.errors, :status => > :unprocessable_entity } > end > end > end > > # DELETE /users/1 > # DELETE /users/1.xml > def destroy > @user = User.find(params[:id]) > @user.destroy > > respond_to do |format| > format.html { redirect_to(users_url) } > format.xml { head :ok } > 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 -~----------~----~----~----~------~----~------~--~---
Michael Breen wrote:> What does the form partial look like?here you go <%= error_messages_for :user %> <% form_for(@user) do |f| %> <h1>Personal Details</h1> <table> <tr> <td> <b>ImageName</b><br> <%= f.text_field :ImageName %> </td> <td> <b>Surname</b><br> <%= f.text_field :SurName %> </td> <td> <b>Forename</b><br> <%= f.text_field :ForeName %> </td> <td> <b>Title</b><br> <%= f.text_field :Title %> </td> </tr> <tr> <td> <b>Room No</b><br> <%= f.text_field :RoomNo %> </td> <td> <b>Phone No</b><br> <%= f.text_field :PhoneNo %> </td> <td> <b>EMail</b><br> <%= f.text_field :EMail %> </td> </tr> </table> <p> <%= f.submit "Save" %> </p> <% 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 -~----------~----~----~----~------~----~------~--~---
Michael Breen wrote:> What does the form partial look like?I''ve also noted that the destroy option doesn''t delete records either. -- 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 -~----------~----~----~----~------~----~------~--~---
>>Do I need to add a @users.save command or something?update_attributes returns true if the save was successful. On Jun 4, 6:57 am, Dale Cunnigham <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> It seems rather odd but my application will happily allow me to add new > records via my form, but using the same form partial the edit action > seems to work fine (It throws no errors) but completely fails to change > the database in any way. Do I need to add a @users.save command or > something? > > Here is my UsersController code > > class UsersController < ApplicationController > # GET /users > # GET /users.xml > def index > if params[:usersearch].blank? > @users = User.find(:all) > else > > @users = User.find(:all, :conditions => [''Surname LIKE ? or > Forename LIKE ? or Position_Group LIKE ?'', "%#{params[:usersearch]}%", > "%#{params[:usersearch]}%", "%#{params[:usersearch]}%"]) > end > > respond_to do |format| > format.html # index.html.erb > format.xml { render :xml => @users } > end > end > > # GET /users/1 > # GET /users/1.xml > def show > @user = User.find(params[:id]) > > respond_to do |format| > format.html # show.html.erb > format.xml { render :xml => @user } > end > end > > # GET /users/new > # GET /users/new.xml > def new > @user = User.new > > respond_to do |format| > format.html # new.html.erb > format.xml { render :xml => @user } > end > end > > # GET /users/1/edit > def edit > @user = User.find(params[:id]) > end > > # POST /users > # POST /users.xml > def create > @user = User.new(params[:user]) > > respond_to do |format| > if @user.save > flash[:notice] = ''User was successfully created.'' > format.html { redirect_to(@user) } > format.xml { render :xml => @user, :status => :created, > :location => @user } > else > format.html { render :action => "new" } > format.xml { render :xml => @user.errors, :status => > :unprocessable_entity } > end > end > end > > # PUT /users/1 > # PUT /users/1.xml > def update > @user = User.find(params[:id]) > > respond_to do |format| > if @user.update_attributes(params[:user]) > flash[:notice] = ''User was successfully updated.'' > format.html { redirect_to(@user) } > format.xml { head :ok } > else > format.html { render :action => "edit" } > format.xml { render :xml => @user.errors, :status => > :unprocessable_entity } > end > end > end > > # DELETE /users/1 > # DELETE /users/1.xml > def destroy > @user = User.find(params[:id]) > @user.destroy > > respond_to do |format| > format.html { redirect_to(users_url) } > format.xml { head :ok } > end > end > end > -- > Posted viahttp://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 -~----------~----~----~----~------~----~------~--~---
You say that you don''t get any errors but what happens when you hit save? Does it redirect to the edit or show action? On Jun 4, 8:51 am, Dale Cunnigham <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Michael Breen wrote: > > What does the form partial look like? > > I''ve also noted that the destroy option doesn''t delete records either. > -- > Posted viahttp://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 -~----------~----~----~----~------~----~------~--~---
Mike Breen wrote:> You say that you don''t get any errors but what happens when you hit > save? Does it redirect to the edit or show action? > > On Jun 4, 8:51 am, Dale Cunnigham <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>It redirects to the show action. -- 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 -~----------~----~----~----~------~----~------~--~---
hmmm...did you check the log or watch the output of script/server? On Jun 4, 2008, at 10:03 AM, Dale Cunnigham wrote:> > Mike Breen wrote: >> You say that you don''t get any errors but what happens when you hit >> save? Does it redirect to the edit or show action? >> >> On Jun 4, 8:51 am, Dale Cunnigham <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > > It redirects to the show action. > -- > 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 -~----------~----~----~----~------~----~------~--~---
Michael Breen wrote:> hmmm...did you check the log or watch the output of script/server?Here is the last entry the one that occurs when I click the save button. Processing UsersController#index (for 134.225.101.126 at 2008-06-04 16:00:10) [PUT] Session ID: random stuff Parameters: {"user"=>{"CorrectEditedForeName"=>"", "SurName"=>"CorrectEditedTestName", PhoneNo"=>"6609", "Duties"=>"", "RoomNo"=>"1L38", "commit"=>"Save", authenticity_token"=>"random digits ive removed", "_method"=>"put", "action"=>"index", "controller"=>"users"} [4;36;1mUser Load (0.431220) [0m [0;1mSELECT * FROM `users` [0m Rendering template within layouts/users Rendering users/index [4;35;1mUser Columns (0.013844) [0m [0mSHOW FIELDS FROM `users` [0m Completed in 1.15826 (0 reqs/sec) | Rendering: 0.52547 (45%) | DB: 0.44506 (38%) | 200 OK [http://webaddress/users/users/] It seems to look ok no? -- 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 -~----------~----~----~----~------~----~------~--~---
> Parameters: {"user"=>{"CorrectEditedForeName"=>"",should be: {"user"=>{"ForeName"=>"CorrectEditedForeName", -- 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 -~----------~----~----~----~------~----~------~--~---
John Yerhot wrote:>> Parameters: {"user"=>{"CorrectEditedForeName"=>"", > should be: > {"user"=>{"ForeName"=>"CorrectEditedForeName",Yep it is, my paste is not precise since I''ve edited it to protect the innocent :D I wouldn''t have thought the error was going to be in the data. -- 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 -~----------~----~----~----~------~----~------~--~---
Are your routes set up properly? What''s your output from rake routes? (I''m just going through the normal troubleshooting steps I would take to track this down. if you don''t think I''m helping please feel free to ignore me ;) On Jun 4, 2008, at 11:49 AM, Dale Cunnigham wrote:> > John Yerhot wrote: >>> Parameters: {"user"=>{"CorrectEditedForeName"=>"", >> should be: >> {"user"=>{"ForeName"=>"CorrectEditedForeName", > > Yep it is, my paste is not precise since I''ve edited it to protect the > innocent :D > > I wouldn''t have thought the error was going to be in the data. > -- > 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 -~----------~----~----~----~------~----~------~--~---
Michael Breen wrote:> Are your routes set up properly? What''s your output from rake routes? > > (I''m just going through the normal troubleshooting steps I would take > to track this down. if you don''t think I''m helping please feel free to > ignore me ;)users GET /users {:controller=>"users", :action=>"index"} formatted_users GET /users.:format {:controller=>"users", :action=>"index"} POST /users {:controller=>"users", :action=>"create"} POST /users.:format {:controller=>"users", :action=>"create"} new_user GET /users/new {:controller=>"users", :action=>"new"} formatted_new_user GET /users/new.:format {:controller=>"users", :action=>"new"} edit_user GET /users/:id/edit {:controller=>"users", :action=>"edit"} formatted_edit_user GET /users/:id/edit.:format {:controller=>"users", :action=>"edit"} user GET /users/:id {:controller=>"users", :action=>"show"} formatted_user GET /users/:id.:format {:controller=>"users", :action=>"show"} PUT /users/:id {:controller=>"users", :action=>"update"} PUT /users/:id.:format {:controller=>"users", :action=>"update"} DELETE /users/:id {:controller=>"users", :action=>"destroy"} DELETE /users/:id.:format {:controller=>"users", :action=>"destroy"} root / {:controller=>"users", :action=>"index"} /:controller/:action/:id /:controller/:action/:id.:format -- 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 -~----------~----~----~----~------~----~------~--~---
> ive removed", "_method"=>"put", "action"=>"index",Looks like a routing issue to me, should be calling the update action... you could try explicitly calling update and see if it works... <% form_for :user, @user, :url => { :action => "update" } do |f| %> -- 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 -~----------~----~----~----~------~----~------~--~---
Did this problem start when you put the form in the partial? You could try this: view/users/edit.html.erb <%= error_messages_for :user %> <% form_for(@user) do |f| %> <%= render :partial => ''deliverable_form'', :locals => { :f => f } %> <%# if you''re using 2.1 there is a nicer way: http://workswithruby.com/2008/4/5-rails-tips %> <p> <%= f.submit "Save" %> </p> put this in view/users/_form.html.erb <h1>Personal Details</h1> <table> <tr> <td> <b>ImageName</b><br> <%= f.text_field :ImageName %> </td> <td> <b>Surname</b><br> <%= f.text_field :SurName %> </td> <td> <b>Forename</b><br> <%= f.text_field :ForeName %> </td> <td> <b>Title</b><br> <%= f.text_field :Title %> </td> </tr> <tr> <td> <b>Room No</b><br> <%= f.text_field :RoomNo %> </td> <td> <b>Phone No</b><br> <%= f.text_field :PhoneNo %> </td> <td> <b>EMail</b><br> <%= f.text_field :EMail %> </td> </tr> </table> On Jun 4, 2008, at 12:13 PM, John Yerhot wrote:> >> ive removed", "_method"=>"put", "action"=>"index", > > Looks like a routing issue to me, should be calling the update > action... > you could try explicitly calling update and see if it works... > <% form_for :user, @user, :url => { :action => "update" } do |f| %> > -- > 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 -~----------~----~----~----~------~----~------~--~---
You can also check the html that is being rendered for the edit action and make sure that the form has the right action. On Jun 4, 2008, at 12:13 PM, John Yerhot wrote:> >> ive removed", "_method"=>"put", "action"=>"index", > > Looks like a routing issue to me, should be calling the update > action... > you could try explicitly calling update and see if it works... > <% form_for :user, @user, :url => { :action => "update" } do |f| %> > -- > 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 -~----------~----~----~----~------~----~------~--~---
Ramon Miguel M. Tayag
2008-Jun-04 19:11 UTC
Re: Newbie: Why doe New work but edit/update not?
You on FastCGI? hostingrails.com has this problem when you''re on FastCGI and REST. On Wed, Jun 4, 2008 at 6:57 PM, Dale Cunnigham <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > It seems rather odd but my application will happily allow me to add new > records via my form, but using the same form partial the edit action > seems to work fine (It throws no errors) but completely fails to change > the database in any way. Do I need to add a @users.save command or > something? > > Here is my UsersController code > > class UsersController < ApplicationController > # GET /users > # GET /users.xml > def index > if params[:usersearch].blank? > @users = User.find(:all) > else > > @users = User.find(:all, :conditions => [''Surname LIKE ? or > Forename LIKE ? or Position_Group LIKE ?'', "%#{params[:usersearch]}%", > "%#{params[:usersearch]}%", "%#{params[:usersearch]}%"]) > end > > respond_to do |format| > format.html # index.html.erb > format.xml { render :xml => @users } > end > end > > # GET /users/1 > # GET /users/1.xml > def show > @user = User.find(params[:id]) > > respond_to do |format| > format.html # show.html.erb > format.xml { render :xml => @user } > end > end > > # GET /users/new > # GET /users/new.xml > def new > @user = User.new > > respond_to do |format| > format.html # new.html.erb > format.xml { render :xml => @user } > end > end > > # GET /users/1/edit > def edit > @user = User.find(params[:id]) > end > > # POST /users > # POST /users.xml > def create > @user = User.new(params[:user]) > > respond_to do |format| > if @user.save > flash[:notice] = ''User was successfully created.'' > format.html { redirect_to(@user) } > format.xml { render :xml => @user, :status => :created, > :location => @user } > else > format.html { render :action => "new" } > format.xml { render :xml => @user.errors, :status => > :unprocessable_entity } > end > end > end > > # PUT /users/1 > # PUT /users/1.xml > def update > @user = User.find(params[:id]) > > respond_to do |format| > if @user.update_attributes(params[:user]) > flash[:notice] = ''User was successfully updated.'' > format.html { redirect_to(@user) } > format.xml { head :ok } > else > format.html { render :action => "edit" } > format.xml { render :xml => @user.errors, :status => > :unprocessable_entity } > end > end > end > > # DELETE /users/1 > # DELETE /users/1.xml > def destroy > @user = User.find(params[:id]) > @user.destroy > > respond_to do |format| > format.html { redirect_to(users_url) } > format.xml { head :ok } > end > end > end > -- > Posted via http://www.ruby-forum.com/. > > > >-- Ramon Tayag --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Really? I have 4 RESTful sites deployed to hostingrails.com all running on FastCGI and haven''t had a single issue. On Jun 4, 2008, at 3:11 PM, Ramon Miguel M. Tayag wrote:> > You on FastCGI? > > hostingrails.com has this problem when you''re on FastCGI and REST. > > On Wed, Jun 4, 2008 at 6:57 PM, Dale Cunnigham > <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote: >> >> It seems rather odd but my application will happily allow me to add >> new >> records via my form, but using the same form partial the edit action >> seems to work fine (It throws no errors) but completely fails to >> change >> the database in any way. Do I need to add a @users.save command or >> something? >> >> Here is my UsersController code >> >> class UsersController < ApplicationController >> # GET /users >> # GET /users.xml >> def index >> if params[:usersearch].blank? >> @users = User.find(:all) >> else >> >> @users = User.find(:all, :conditions => [''Surname LIKE ? or >> Forename LIKE ? or Position_Group LIKE ?'', "%#{params[:usersearch]} >> %", >> "%#{params[:usersearch]}%", "%#{params[:usersearch]}%"]) >> end >> >> respond_to do |format| >> format.html # index.html.erb >> format.xml { render :xml => @users } >> end >> end >> >> # GET /users/1 >> # GET /users/1.xml >> def show >> @user = User.find(params[:id]) >> >> respond_to do |format| >> format.html # show.html.erb >> format.xml { render :xml => @user } >> end >> end >> >> # GET /users/new >> # GET /users/new.xml >> def new >> @user = User.new >> >> respond_to do |format| >> format.html # new.html.erb >> format.xml { render :xml => @user } >> end >> end >> >> # GET /users/1/edit >> def edit >> @user = User.find(params[:id]) >> end >> >> # POST /users >> # POST /users.xml >> def create >> @user = User.new(params[:user]) >> >> respond_to do |format| >> if @user.save >> flash[:notice] = ''User was successfully created.'' >> format.html { redirect_to(@user) } >> format.xml { render :xml => @user, :status => :created, >> :location => @user } >> else >> format.html { render :action => "new" } >> format.xml { render :xml => @user.errors, :status => >> :unprocessable_entity } >> end >> end >> end >> >> # PUT /users/1 >> # PUT /users/1.xml >> def update >> @user = User.find(params[:id]) >> >> respond_to do |format| >> if @user.update_attributes(params[:user]) >> flash[:notice] = ''User was successfully updated.'' >> format.html { redirect_to(@user) } >> format.xml { head :ok } >> else >> format.html { render :action => "edit" } >> format.xml { render :xml => @user.errors, :status => >> :unprocessable_entity } >> end >> end >> end >> >> # DELETE /users/1 >> # DELETE /users/1.xml >> def destroy >> @user = User.find(params[:id]) >> @user.destroy >> >> respond_to do |format| >> format.html { redirect_to(users_url) } >> format.xml { head :ok } >> end >> end >> end >> -- >> Posted via http://www.ruby-forum.com/. >> >>> >> > > > > -- > Ramon Tayag > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
John Yerhot wrote:>> ive removed", "_method"=>"put", "action"=>"index", > > Looks like a routing issue to me, should be calling the update action... > you could try explicitly calling update and see if it works... > <% form_for :user, @user, :url => { :action => "update" } do |f| %>Ok I moved the form back into the edit and new html.erb files and then added replaced <% form_for(@user) do |f| %> with <% form_for :user, @user, :url => { :action => "update" } do |f| %> in the the edit.html.erb file On clicking the save button I get redirected to the url http://www.website.com/users/users/1221 and get the following error Unknown action No action responded to 1221 I guess I need to do something with routing for the edit action. I was trying to stick with just using ActionController::Routing::Routes.draw do |map| map.resources :users map.root :controller => "users" map.connect '':controller/:action/:id'' map.connect '':controller/:action/:id.:format'' 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 -~----------~----~----~----~------~----~------~--~---
try sticking with <% form_for(@user) do |f| %> On Jun 5, 2008, at 5:57 AM, Dale Cunnigham wrote:> > John Yerhot wrote: >>> ive removed", "_method"=>"put", "action"=>"index", >> >> Looks like a routing issue to me, should be calling the update >> action... >> you could try explicitly calling update and see if it works... >> <% form_for :user, @user, :url => { :action => "update" } do |f| %> > > Ok I moved the form back into the edit and new html.erb files > > and then added replaced <% form_for(@user) do |f| %> with <% form_for > :user, @user, :url => { :action => "update" } do |f| %> in the the > edit.html.erb file > > On clicking the save button I get redirected to the url > > http://www.website.com/users/users/1221 > > and get the following error > > Unknown action > > No action responded to 1221 > > I guess I need to do something with routing for the edit action. > > I was trying to stick with just using > > ActionController::Routing::Routes.draw do |map| > map.resources :users > map.root :controller => "users" > map.connect '':controller/:action/:id'' > map.connect '':controller/:action/:id.:format'' > 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 -~----------~----~----~----~------~----~------~--~---
Michael Breen wrote:> try sticking with <% form_for(@user) do |f| %>If I go with that I''m back to the original problem. No errors and it just doesn''t write changes to the database. The Logfile has the following entries for the attempted edit... Processing UsersController#edit (for IPADDRESS at 2008-06-05 13:31:58) [GET] Session ID: BAh7BzoMY3NyZl9pZCIlM2RkOTljMTk3YzE2MWQwMTY3MTNhN2NlZTc5OTFm%0ANWIiCmZsYXNoSUM6J0FjdGlvbkNvbnRyb2xsZXI6OkZsYXNoOjpGbGFzaEhh%0Ac2h7AAY6CkB1c2VkewA%3D--92ba3187f08e3b00058aa442cdf467c0efde5102 Parameters: {"action"=>"edit", "id"=>"1222", "controller"=>"users"} [4;36;1mUser Columns (0.013465) [0m [0;1mSHOW FIELDS FROM `users` [0m [4;35;1mUser Load (0.011432) [0m [0mSELECT * FROM `users` WHERE (`users`.`id` = ''1222'') [0m Rendering template within layouts/users Rendering users/edit Completed in 0.10657 (9 reqs/sec) | Rendering: 0.05074 (47%) | DB: 0.02490 (23%) | 200 OK [http://www.met.rdg.ac.uk/users/users/1222/edit] Processing UsersController#index (for IPADDRESS at 2008-06-05 13:32:04) [PUT] Session ID: BAh7BzoMY3NyZl9pZCIlM2RkOTljMTk3YzE2MWQwMTY3MTNhN2NlZTc5OTFm%0ANWIiCmZsYXNoSUM6J0FjdGlvbkNvbnRyb2xsZXI6OkZsYXNoOjpGbGFzaEhh%0Ac2h7AAY6CkB1c2VkewA%3D--92ba3187f08e3b00058aa442cdf467c0efde5102 Parameters: {"user"=>{"SurName"=>"test 3", "Title"=>"Mr", "EMail"=>"tester-nwB1Ag/q++a9FHfhHBbuYA@public.gmane.org", "ForeName"=>"Donny", "RoomNo"=>"3F546"}, "commit"=>"Save", "authenticity_token"=>"tokendigits", "_method"=>"put", "action"=>"index", "controller"=>"users"} [4;36;1mUser Load (0.280259) [0m [0;1mSELECT * FROM `users` [0m Rendering template within layouts/users Rendering users/index [4;35;1mUser Columns (0.013465) [0m [0mSHOW FIELDS FROM `users` [0m Completed in 0.99386 (1 reqs/sec) | Rendering: 0.51505 (51%) | DB: 0.29372 (29%) | 200 OK [http://www.website.com/users/users/] -- 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 -~----------~----~----~----~------~----~------~--~---
The urls are not correct: http://www.met.rdg.ac.uk/users/users/1222/edit Earlier I suggested that you look at the html rendered by your templates (view source in your browser or firebug). For whatever reason the action on your forms is not correct. On Jun 5, 2008, at 8:38 AM, Dale Cunnigham wrote:> > Michael Breen wrote: >> try sticking with <% form_for(@user) do |f| %> > > If I go with that I''m back to the original problem. No errors and it > just doesn''t write changes to the database. > > The Logfile has the following entries for the attempted edit... > > > Processing UsersController#edit (for IPADDRESS at 2008-06-05 13:31:58) > [GET] > Session ID: > BAh7BzoMY3NyZl9pZCIlM2RkOTljMTk3YzE2MWQwMTY3MTNhN2NlZTc5OTFm > %0ANWIiCmZsYXNoSUM6J0FjdGlvbkNvbnRyb2xsZXI6OkZsYXNoOjpGbGFzaEhh > %0Ac2h7AAY6CkB1c2VkewA%3D--92ba3187f08e3b00058aa442cdf467c0efde5102 > Parameters: {"action"=>"edit", "id"=>"1222", "controller"=>"users"} > [4;36;1mUser Columns (0.013465) [0m [0;1mSHOW FIELDS FROM > `users` [0m > [4;35;1mUser Load (0.011432) [0m [0mSELECT * FROM `users` WHERE > (`users`.`id` = ''1222'') [0m > Rendering template within layouts/users > Rendering users/edit > Completed in 0.10657 (9 reqs/sec) | Rendering: 0.05074 (47%) | DB: > 0.02490 (23%) | 200 OK [http://www.met.rdg.ac.uk/users/users/1222/ > edit] > > > Processing UsersController#index (for IPADDRESS at 2008-06-05 > 13:32:04) > [PUT] > Session ID: > BAh7BzoMY3NyZl9pZCIlM2RkOTljMTk3YzE2MWQwMTY3MTNhN2NlZTc5OTFm > %0ANWIiCmZsYXNoSUM6J0FjdGlvbkNvbnRyb2xsZXI6OkZsYXNoOjpGbGFzaEhh > %0Ac2h7AAY6CkB1c2VkewA%3D--92ba3187f08e3b00058aa442cdf467c0efde5102 > Parameters: {"user"=>{"SurName"=>"test 3", "Title"=>"Mr", > "EMail"=>"tester-nwB1Ag/q++a9FHfhHBbuYA@public.gmane.org", "ForeName"=>"Donny", > "RoomNo"=>"3F546"}, "commit"=>"Save", > "authenticity_token"=>"tokendigits", "_method"=>"put", > "action"=>"index", "controller"=>"users"} > [4;36;1mUser Load (0.280259) [0m [0;1mSELECT * FROM `users` [0m > Rendering template within layouts/users > Rendering users/index > [4;35;1mUser Columns (0.013465) [0m [0mSHOW FIELDS FROM > `users` [0m > Completed in 0.99386 (1 reqs/sec) | Rendering: 0.51505 (51%) | DB: > 0.29372 (29%) | 200 OK [http://www.website.com/users/users/] > -- > 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 -~----------~----~----~----~------~----~------~--~---
The edit action should be posting to the update action, not index action. Check the html output for your edit page. The form tag should look something like this: <form action="/users/1222" class="edit_user" id="edit_user_1222" method="post"> On Jun 5, 2008, at 8:38 AM, Dale Cunnigham wrote:> > Michael Breen wrote: >> try sticking with <% form_for(@user) do |f| %> > > If I go with that I''m back to the original problem. No errors and it > just doesn''t write changes to the database. > > The Logfile has the following entries for the attempted edit... > > > Processing UsersController#edit (for IPADDRESS at 2008-06-05 13:31:58) > [GET] > Session ID: > BAh7BzoMY3NyZl9pZCIlM2RkOTljMTk3YzE2MWQwMTY3MTNhN2NlZTc5OTFm > %0ANWIiCmZsYXNoSUM6J0FjdGlvbkNvbnRyb2xsZXI6OkZsYXNoOjpGbGFzaEhh > %0Ac2h7AAY6CkB1c2VkewA%3D--92ba3187f08e3b00058aa442cdf467c0efde5102 > Parameters: {"action"=>"edit", "id"=>"1222", "controller"=>"users"} > [4;36;1mUser Columns (0.013465) [0m [0;1mSHOW FIELDS FROM > `users` [0m > [4;35;1mUser Load (0.011432) [0m [0mSELECT * FROM `users` WHERE > (`users`.`id` = ''1222'') [0m > Rendering template within layouts/users > Rendering users/edit > Completed in 0.10657 (9 reqs/sec) | Rendering: 0.05074 (47%) | DB: > 0.02490 (23%) | 200 OK [http://www.met.rdg.ac.uk/users/users/1222/ > edit] > > > Processing UsersController#index (for IPADDRESS at 2008-06-05 > 13:32:04) > [PUT] > Session ID: > BAh7BzoMY3NyZl9pZCIlM2RkOTljMTk3YzE2MWQwMTY3MTNhN2NlZTc5OTFm > %0ANWIiCmZsYXNoSUM6J0FjdGlvbkNvbnRyb2xsZXI6OkZsYXNoOjpGbGFzaEhh > %0Ac2h7AAY6CkB1c2VkewA%3D--92ba3187f08e3b00058aa442cdf467c0efde5102 > Parameters: {"user"=>{"SurName"=>"test 3", "Title"=>"Mr", > "EMail"=>"tester-nwB1Ag/q++a9FHfhHBbuYA@public.gmane.org", "ForeName"=>"Donny", > "RoomNo"=>"3F546"}, "commit"=>"Save", > "authenticity_token"=>"tokendigits", "_method"=>"put", > "action"=>"index", "controller"=>"users"} > [4;36;1mUser Load (0.280259) [0m [0;1mSELECT * FROM `users` [0m > Rendering template within layouts/users > Rendering users/index > [4;35;1mUser Columns (0.013465) [0m [0mSHOW FIELDS FROM > `users` [0m > Completed in 0.99386 (1 reqs/sec) | Rendering: 0.51505 (51%) | DB: > 0.29372 (29%) | 200 OK [http://www.website.com/users/users/] > -- > 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 -~----------~----~----~----~------~----~------~--~---
Michael Breen wrote:> The edit action should be posting to the update action, not index > action. > > Check the html output for your edit page. The form tag should look > something like this: > > <form action="/users/1222" class="edit_user" id="edit_user_1222" > method="post">Interesting, the page source seems to have left the ID out so I''m getting <form action="/users/users/" class="edit_user" id="edit_user" method="post"> instead of <form action="/users/1222" class="edit_user" id="edit_user_1222" method="post"> Shouldn''t <% form_for(@user) do |f| %> <%= f.submit "Save" %> <% End %> do this automatically? -- 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 -~----------~----~----~----~------~----~------~--~---
perhaps somebody can post an example ActionController that works along with an example routes.rb file/correct urls so I can figure out my next step? Most of the tutorials for this stuff seem to be for rails 1.2 -- 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 -~----------~----~----~----~------~----~------~--~---
create a dummy project and then run script/generate scaffold User first_name:string last_name:string that will give you a good example RESTful controller. easier than someone posting that code. On Jun 5, 2008, at 11:51 AM, Dale Cunnigham wrote:> > perhaps somebody can post an example ActionController that works along > with an example routes.rb file/correct urls so I can figure out my > next > step? > > Most of the tutorials for this stuff seem to be for rails 1.2 > -- > 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 -~----------~----~----~----~------~----~------~--~---
Michael Breen wrote:> create a dummy project and then run script/generate scaffold User > first_name:string last_name:string > > that will give you a good example RESTful controller. easier than > someone posting that code.This is getting weird now. I''ve done the following rails testproj script/generate scaffold user ForeName:string SurName:string and the generated UsersController code for update and delete is identical to what I have for my user project, and the only difference inthe routes.rb file is the line, map.root :controller => "users" I''m kind of at a loss :( If my database was not allowing update access it rails would throw an exception wouldn''t it? -- 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 -~----------~----~----~----~------~----~------~--~---