I am trying to update a leave but the update does not work. Please let
me know where I am making the mistake.(Looked in to the log, id in the
update SQL statment shows NULL)
View
<h1>Editing Leaves</h1>
<% form_for :leaves, @leaves, :url => { :controller =>
"leaves", :action => "update" } do |f| %>
<%= f.text_field :id%>
<b>Leave Type</b>
<%= f.text_field :LEAVE_TYPE %><br>
<b>FROM_DATE</b>
<%= f.text_field :FROM_DATE %><br>
<b>TO Date</b>
<%= f.text_field :TO_DATE %><br>
<b>Phone Number</b>
<%= f.text_field :PHONE_NUMBER %><br>
<b>Address</b>
<%= f.text_field :ADDRESS %><br>
<b>Reason for Leave</b>
<%= f.text_area :REASON_FOR_LEAVE %><br>
<%= f.submit "update" %>
<% end %>
<%= error_messages_for :leaves %>
Controller''s update method
def update
@leaves=Leave.find(params[:id])
if @leaves.update_attributes(params[:leave])
#~ puts(@leaves.ID)
flash[:notice] = ''Leave was successfully updated.''
redirect_to :action => ''show'', :id =>
@leaves.ID
else
render :action => ''edit''
end
end
I looked in to the log and looks like the id in update statement is
going NULL what could be the problem for this and how can I fix this.
[0mSELECT * FROM `leaves` WHERE (`leaves`.`id` = ''2'') [0m
[4;36;1mSQL (0.000000) [0m [0;1mBEGIN [0m
[4;35;1mLeave Update (0.000000) [0m [0mUPDATE `leaves` SET
`FROM_DATE` = ''2008-11-05'', `REASON_FOR_CANCELLATION` = NULL,
`BACKUP`
= NULL, `EMP_ID` = 90268, `TO_DATE` = ''2008-11-09'', `ADDRESS`
= NULL,
`MGR_EMP_ID` = 90000, `MANAGER_COMMENTS` = NULL, `REASON_FOR_LEAVE` NULL,
`LEAVE_TYPE` = ''leave'', `ID` = 2, `APPLIED_ON_DATE`
''2008-09-15'', `PHONE_NUMBER` = NULL, `LEAVE_STATUS` =
''PENDING'' WHERE
`id` = NULL
--~--~---------~--~----~------------~-------~--~----~
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@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2008-Oct-18 16:18 UTC
Re: update _attribtutes fails to update, please help!
On Oct 18, 5:15 pm, rvruby <xtendedmem...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I am trying to update a leave but the update does not work. Please let > me know where I am making the mistake.(Looked in to the log, id in the > update SQL statment shows NULL) > > View > > <h1>Editing Leaves</h1> > <% form_for :leaves, @leaves, :url => { :controller => > "leaves", :action => "update" } do |f| %> > <%= f.text_field :id%>That''s really not a good idea. remove that text field. Fred --~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
I included the <%= f.text_field :id%> just to verify. Even after I
removed it, it does not work.
Please help.
Processing LeavesController#update (for 127.0.0.1 at 2008-10-19
01:18:59) [POST]
Session ID:
BAh7CjoRZW1wc21ncmVtcGlkaQOQXwE6DGNzcmZfaWQiJTViZTdjMmU1ZDk1%0AZWRlODc5OTM2YjMzMjdiNWRjNTc5OgplbXBpZCIKOTAyNjgiCmZsYXNoSUM6%0AJ0FjdGlvbkNvbnRyb2xsZXI6OkZsYXNoOjpGbGFzaEhhc2h7AAY6CkB1c2Vk
%0AewA6DG1ncm5hbWUiF2Jvc3NmbmFtZWJvc3NsbmFtZQ%3D
%3D--1afd388b96433710a23047adc0f38b57c3422517
Parameters: {"commit"=>"update",
"authenticity_token"=>"949d78977aa51943832f36c2768c785f8d5bbbc7",
"action"=>"update", "id"=>"4",
"leaves"=>{"TO_DATE"=>"2008-12-31",
"FROM_DATE"=>"2008-12-30",
"LEAVE_TYPE"=>"compoff",
"REASON_FOR_LEAVE"=>"Updated Reason for leave",
"PHONE_NUMBER"=>"",
"ADDRESS"=>""},
"controller"=>"leaves"}
[4;36;1mLeave Columns (0.000000) [0m [0;1mSHOW FIELDS FROM
`leaves` [0m
[4;35;1mLeave Load (0.000000) [0m [0mSELECT * FROM `leaves`
WHERE (`leaves`.`id` = ''4'') [0m
[4;36;1mSQL (0.000000) [0m [0;1mBEGIN [0m
[4;35;1mLeave Update (0.000000) [0m [0mUPDATE `leaves` SET
`FROM_DATE` = ''2008-12-30'', `REASON_FOR_CANCELLATION` = NULL,
`BACKUP`
= NULL, `EMP_ID` = 90268, `TO_DATE` = ''2008-12-31'', `ADDRESS`
= NULL,
`MGR_EMP_ID` = 90000, `MANAGER_COMMENTS` = NULL, `REASON_FOR_LEAVE` NULL,
`LEAVE_TYPE` = ''compoff'', `ID` = 4, `APPLIED_ON_DATE`
''2008-11-28'', `PHONE_NUMBER` = NULL, `LEAVE_STATUS` =
''PENDING'' WHERE
`id` = NULL
On Oct 18, 9:18 pm, Frederick Cheung
<frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> On Oct 18, 5:15 pm, rvruby
<xtendedmem...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I am
trying to update a leave but the update does not work. Please let
> > me know where I am making the mistake.(Looked in to the log, id in the
> > update SQL statment shows NULL)
>
> > View
>
> > <h1>Editing Leaves</h1>
> > <% form_for :leaves, @leaves, :url => { :controller =>
> > "leaves", :action => "update" } do |f| %>
> > <%= f.text_field :id%>
>
> That''s really not a good idea. remove that text field.
>
> Fred
--~--~---------~--~----~------------~-------~--~----~
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@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2008-Oct-18 19:57 UTC
Re: update _attribtutes fails to update, please help!
Is your primary key column not called id? If so you need to use set_primary_key Sent from my iPhone On 18 Oct 2008, at 20:53, rvruby <xtendedmemory-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > I included the <%= f.text_field :id%> just to verify. Even after I > removed it, it does not work. > > Please help. > > Processing LeavesController#update (for 127.0.0.1 at 2008-10-19 > 01:18:59) [POST] > Session ID: > BAh7CjoRZW1wc21ncmVtcGlkaQOQXwE6DGNzcmZfaWQiJTViZTdjMmU1ZDk1% > 0AZWRlODc5OTM2YjMzMjdiNWRjNTc5OgplbXBpZCIKOTAyNjgiCmZsYXNoSUM6% > 0AJ0FjdGlvbkNvbnRyb2xsZXI6OkZsYXNoOjpGbGFzaEhhc2h7AAY6CkB1c2Vk > %0AewA6DG1ncm5hbWUiF2Jvc3NmbmFtZWJvc3NsbmFtZQ%3D > %3D--1afd388b96433710a23047adc0f38b57c3422517 > Parameters: {"commit"=>"update", > "authenticity_token"=>"949d78977aa51943832f36c2768c785f8d5bbbc7", > "action"=>"update", "id"=>"4", "leaves"=>{"TO_DATE"=>"2008-12-31", > "FROM_DATE"=>"2008-12-30", "LEAVE_TYPE"=>"compoff", > "REASON_FOR_LEAVE"=>"Updated Reason for leave", "PHONE_NUMBER"=>"", > "ADDRESS"=>""}, "controller"=>"leaves"} > [4;36;1mLeave Columns (0.000000) [0m [0;1mSHOW FIELDS FROM > `leaves` [0m > [4;35;1mLeave Load (0.000000) [0m [0mSELECT * FROM `leaves` > WHERE (`leaves`.`id` = ''4'') [0m > [4;36;1mSQL (0.000000) [0m [0;1mBEGIN [0m > [4;35;1mLeave Update (0.000000) [0m [0mUPDATE `leaves` SET > `FROM_DATE` = ''2008-12-30'', `REASON_FOR_CANCELLATION` = NULL, `BACKUP` > = NULL, `EMP_ID` = 90268, `TO_DATE` = ''2008-12-31'', `ADDRESS` = NULL, > `MGR_EMP_ID` = 90000, `MANAGER_COMMENTS` = NULL, `REASON_FOR_LEAVE` > NULL, `LEAVE_TYPE` = ''compoff'', `ID` = 4, `APPLIED_ON_DATE` > ''2008-11-28'', `PHONE_NUMBER` = NULL, `LEAVE_STATUS` = ''PENDING'' WHERE > `id` = NULL > > On Oct 18, 9:18 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: >> On Oct 18, 5:15 pm, rvruby <xtendedmem...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I am >> trying to update a leave but the update does not work. Please let >>> me know where I am making the mistake.(Looked in to the log, id in >>> the >>> update SQL statment shows NULL) >> >>> View >> >>> <h1>Editing Leaves</h1> >>> <% form_for :leaves, @leaves, :url => { :controller => >>> "leaves", :action => "update" } do |f| %> >>> <%= f.text_field :id%> >> >> That''s really not a good idea. remove that text field. >> >> Fred > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
in my table ID is the primary key, what surprises me is, in the dev log there is a ID and id with values 4 and null UPDATE `leaves` SET `FROM_DATE` = ''2008-12-30'', `REASON_FOR_CANCELLATION` = NULL, `BACKUP` = NULL, `EMP_ID` = 90268, `TO_DATE` = ''2008-12-31'', `ADDRESS` = NULL, `MGR_EMP_ID` = 90000, `MANAGER_COMMENTS` = NULL, `REASON_FOR_LEAVE` =NULL, `LEAVE_TYPE` = ''compoff'', `ID` = 4, `APPLIED_ON_DATE` =''2008-11-28'', `PHONE_NUMBER` = NULL, `LEAVE_STATUS` = ''PENDING'' WHERE `id` = NULL Thanks for your help. On Oct 19, 12:57 am, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Is your primary key column not called id? If so you need to use > set_primary_key > > Sent from my iPhone >--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
I renamed the ID column to "id" and now instead of NULL I see value in the dev log for the update query. Not getting updated yet, but I think I will nail it down. Thanks for the help. On Oct 19, 1:10 am, rvruby <xtendedmem...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> in my table ID is the primary key, what surprises me is, in the dev > log there is a ID and id with values 4 and null > > UPDATE `leaves` SET `FROM_DATE` = ''2008-12-30'', > `REASON_FOR_CANCELLATION` = NULL, `BACKUP` > = NULL, `EMP_ID` = 90268, `TO_DATE` = ''2008-12-31'', `ADDRESS` = NULL, > `MGR_EMP_ID` = 90000, `MANAGER_COMMENTS` = NULL, `REASON_FOR_LEAVE` > =NULL, `LEAVE_TYPE` = ''compoff'', `ID` = 4, `APPLIED_ON_DATE` > =''2008-11-28'', `PHONE_NUMBER` = NULL, `LEAVE_STATUS` = ''PENDING'' WHERE > `id` = NULL > Thanks for your help. > > On Oct 19, 12:57 am, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: > > > Is your primary key column not called id? If so you need to use > > set_primary_key > > > Sent from my iPhone--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2008-Oct-18 23:46 UTC
Re: update _attribtutes fails to update, please help!
Sent from my iPhone On 18 Oct 2008, at 21:10, rvruby <xtendedmemory-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > in my table ID is the primary key, what surprises me is, in the dev > log there is a ID and id with values 4 and nullid is not the same as ID Fred> > > UPDATE `leaves` SET `FROM_DATE` = ''2008-12-30'', > `REASON_FOR_CANCELLATION` = NULL, `BACKUP` > = NULL, `EMP_ID` = 90268, `TO_DATE` = ''2008-12-31'', `ADDRESS` = NULL, > `MGR_EMP_ID` = 90000, `MANAGER_COMMENTS` = NULL, `REASON_FOR_LEAVE` > =NULL, `LEAVE_TYPE` = ''compoff'', `ID` = 4, `APPLIED_ON_DATE` > =''2008-11-28'', `PHONE_NUMBER` = NULL, `LEAVE_STATUS` = ''PENDING'' WHERE > `id` = NULL > Thanks for your help. > > > On Oct 19, 12:57 am, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: >> Is your primary key column not called id? If so you need to use >> set_primary_key >> >> Sent from my iPhone >> > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---