Hello. Here are the two offending lines of code: They are designed to provide a drop down list (working). @bank =Org.find(:all, :conditions=>"org_type=''bank''") @bank.unshift(Org.new ("name"=>"none","id"=>1000,"addr1"=>"a","addr2"=>"b","city"=>"c","provin ce"=>"d","post_code"=>"x", "country"=>"Canada","gst_number"=>"y","logo"=>"null","parent"=>0,"inv_pr efix"=>"z","org_type"=>"bank")) The problem is that when I inspect the @bank array I find that it does not have an "id" field. This is a problem because it means I cannot save the invoice record. Any ideas? bruce
On 11/18/05, Bruce Balmer <brucebalmer-ee4meeAH724@public.gmane.org> wrote:> Hello. > > Here are the two offending lines of code: They are designed to > provide a drop down list (working). > > @bank =Org.find(:all, :conditions=>"org_type=''bank''") > > @bank.unshift(Org.new > ("name"=>"none","id"=>1000,"addr1"=>"a","addr2"=>"b","city"=>"c","provin > ce"=>"d","post_code"=>"x", > > "country"=>"Canada","gst_number"=>"y","logo"=>"null","parent"=>0,"inv_pr > efix"=>"z","org_type"=>"bank")) > > The problem is that when I inspect the @bank array I find that it > does not have an "id" field. This is a problem because it means I > cannot save the invoice record. > > Any ideas? > > bruce >I had a similar problem last night. Could it be that the ID is supposed to be assigned by the DB on create? That was my guess. Dave
David Clements wrote:> On 11/18/05, Bruce Balmer <brucebalmer-ee4meeAH724@public.gmane.org> wrote: > >>Hello. >> >>Here are the two offending lines of code: They are designed to >>provide a drop down list (working). >> >>@bank =Org.find(:all, :conditions=>"org_type=''bank''") >> >>@bank.unshift(Org.new >>("name"=>"none","id"=>1000,"addr1"=>"a","addr2"=>"b","city"=>"c","provin >>ce"=>"d","post_code"=>"x", >> >>"country"=>"Canada","gst_number"=>"y","logo"=>"null","parent"=>0,"inv_pr >>efix"=>"z","org_type"=>"bank")) >> >>The problem is that when I inspect the @bank array I find that it >>does not have an "id" field. This is a problem because it means I >>cannot save the invoice record. >> >>Any ideas? >> >>bruce >> > > > I had a similar problem last night. Could it be that the ID is > supposed to be assigned by the DB on create? That was my guess.The Model.new and the Model#attributes= methods ignore any setting of the ID to prevent malicious attacks from the client to populate @params and set the id. You have to set it separately, but it''s best to let the DB assign it. Regards, Blair -- Blair Zajac, Ph.D. <blair-szbw9MROnEZWk0Htik3J/w@public.gmane.org> Subversion and Orca training and consulting http://www.orcaware.com/svn/
David: Thanks. I guessed the same but that was helping. So I "cheated". I solved it this way (I''d still like to know what the problem was) if @invoice.bank_id = "null" @invoince.bank_id = 0 Which works for my purpose. These two lines of code come just before the Invoice.save method. It works, but I feel kind of dirty. I feel there is something here that I have not understood that I should have understood. I hope that this workaround / kludge / abuse of ruby purity may be of assistance, if you can''t find a cleaner method. bruce On 18-Nov-05, at 1:27 PM, David Clements wrote:> On 11/18/05, Bruce Balmer <brucebalmer-ee4meeAH724@public.gmane.org> wrote: >> Hello. >> >> Here are the two offending lines of code: They are designed to >> provide a drop down list (working). >> >> @bank =Org.find(:all, :conditions=>"org_type=''bank''") >> >> @bank.unshift(Org.new >> ("name"=>"none","id"=>1000,"addr1"=>"a","addr2"=>"b","city"=>"c","pro >> vin >> ce"=>"d","post_code"=>"x", >> >> "country"=>"Canada","gst_number"=>"y","logo"=>"null","parent"=>0,"inv >> _pr >> efix"=>"z","org_type"=>"bank")) >> >> The problem is that when I inspect the @bank array I find that it >> does not have an "id" field. This is a problem because it means I >> cannot save the invoice record. >> >> Any ideas? >> >> bruce >> > > I had a similar problem last night. Could it be that the ID is > supposed to be assigned by the DB on create? That was my guess. > > Dave > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails
Hello. I have to create a PDF from ruby (partly because browsers are so poor at printing html pages - why is that?). I am looking at PDF::Writer. Does anyone have any suggestions as to a better package than that - if there is one? tia bruce
try using Org.create instead of Org.new (and remove the id attribute of course). create will attempt to save and return the new record. if the object could not be saved, then the unsaved object is returned. @bank.unshift(Org.new("name"=>"none", "addr1"=>"a", "addr2"=>"b", "city"=>"c", "province"=>"d", "post_code"=>"x", "country"=>"Canada", "gst_number"=>"y", "logo"=>"null", "parent"=>0, "inv_prefix"=>"z", "org_type"=>"bank")) On 11/18/05, Blair Zajac <blair-szbw9MROnEZWk0Htik3J/w@public.gmane.org> wrote:> > David Clements wrote: > > On 11/18/05, Bruce Balmer <brucebalmer-ee4meeAH724@public.gmane.org> wrote: > > > >>Hello. > >> > >>Here are the two offending lines of code: They are designed to > >>provide a drop down list (working). > >> > >>@bank =Org.find(:all, :conditions=>"org_type=''bank''") > >> > >>@bank.unshift(Org.new > >>("name"=>"none","id"=>1000,"addr1"=>"a","addr2"=>"b","city"=>"c","provin > >>ce"=>"d","post_code"=>"x", > >> > >>"country"=>"Canada","gst_number"=>"y","logo"=>"null","parent"=>0,"inv_pr > >>efix"=>"z","org_type"=>"bank")) > >> > >>The problem is that when I inspect the @bank array I find that it > >>does not have an "id" field. This is a problem because it means I > >>cannot save the invoice record. > >> > >>Any ideas? > >> > >>bruce > >> > > > > > > I had a similar problem last night. Could it be that the ID is > > supposed to be assigned by the DB on create? That was my guess. > > The Model.new and the Model#attributes= methods ignore any setting of the > ID to > prevent malicious attacks from the client to populate @params and set the > id. > > You have to set it separately, but it''s best to let the DB assign it. > > Regards, > Blair > > -- > Blair Zajac, Ph.D. > <blair-szbw9MROnEZWk0Htik3J/w@public.gmane.org> > Subversion and Orca training and consulting > http://www.orcaware.com/svn/ > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >_______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
On 11/18/05, Bruce Balmer <brucebalmer-ee4meeAH724@public.gmane.org> wrote:> I have to create a PDF from ruby (partly because browsers are so poor > at printing html pages - why is that?). I am looking at > PDF::Writer. Does anyone have any suggestions as to a better package > than that - if there is one?There are multiple packages available, however -- and I will be completely unbiased here ;) -- PDF::Writer is the best option you''ll find for Ruby right now. If, however, you end up not liking the PDF::Writer API, I can recommend that the Ruby implementation of FPDF produces nice looking documents, even though I can''t stand the API. PDF::Writer will be taking some ideas from the original PHP implementation of FPDF for future releases, but the overall capabilities of PDF::Writer are greater than those offered by FPDF. -austin -- Austin Ziegler * halostatue-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org * Alternate: austin-/yODNl0JVVCozMbzO90S/Q@public.gmane.org
On 11/18/05, Bruce Balmer <brucebalmer-ee4meeAH724@public.gmane.org> wrote:> Hello. > > I have to create a PDF from ruby (partly because browsers are so poor > at printing html pages - why is that?). I am looking at > PDF::Writer. Does anyone have any suggestions as to a better package > than that - if there is one? >I did quite a bit of research and found PDF::Writer to be the best solution for ruby. Just got done using it on a project for a client and it''s worked just fine. Chris
+-le 18/11/2005 17:16 -0500, Austin Ziegler écrivait : | On 11/18/05, Bruce Balmer <brucebalmer-ee4meeAH724@public.gmane.org> wrote: |> I have to create a PDF from ruby (partly because browsers are so poor |> at printing html pages - why is that?). I am looking at |> PDF::Writer. Does anyone have any suggestions as to a better package |> than that - if there is one? | | There are multiple packages available, however -- and I will be | completely unbiased here ;) -- PDF::Writer is the best option you''ll | find for Ruby right now. If, however, you end up not liking the | PDF::Writer API, I can recommend that the Ruby implementation of FPDF | produces nice looking documents, even though I can''t stand the API. Plus, using the template handler near the middle of http://wiki.rubyonrails.com/rails/pages/HowtoGeneratePDFs it''s really the nicest thing you can do :-) -- Mathieu Arnold