Valli
2009-Jul-16 09:29 UTC
Find_all_by and find(:all) to only select certain values for a selection box
So....let''s have a look if I understood the issue: -Find_all_by is actually the same like Find(:all), however Find_all_by is much shorter and less complicated than the syntax of Find(:all) -So in my CONTROLLER it says @files = find(:all) however I don''t want to see all files displayed in my selection box, because I only want to see the foles whose mandant_id is the same like the mandant_id in invoice. So i decided to change the @files = find(:all) into => @files File.find_all_by_mandant_id(Invoice.mandant_id) But this doesn´t work so does any one has an inspiration to get it working?? If so please help me!! thnx a lot!! =D Valli
Ar Chron
2009-Jul-16 12:55 UTC
Re: Find_all_by and find(:all) to only select certain values for a selection box
Valli wrote:> So....let''s have a look if I understood the issue: > > -Find_all_by is actually the same like Find(:all), however Find_all_by > is much shorter and less complicated than the syntax of Find(:all) >You need an instance of the Invoice class, not the class... Perhaps something like: @invoice = Invoice.find(params[:id]) @files = File.find_all_by_mandant_id(@invoice.mandant_id ) or @invoice = Invoice.find(params[:id]) @files = File.find(:all, :conditions => [''mandant_id = ?'', @invoice.mandant_id]) -- Posted via http://www.ruby-forum.com/.
Valli
2009-Jul-16 13:16 UTC
Re: Find_all_by and find(:all) to only select certain values for a selection box
thnx a lot for the idea, i really apreciate it!! however it still doesn''t work correctly so anyone has an other suggestion? well i think it could help to update the mandant_id before carrying on with the files_id, because if not the how could the database actually know the new value for the mandant_id??? --> for this I think u need :onchange => "#{remote_function(:url => {:action => "update_sprints"}, :with => "''project_id=''+value")}"}) However i cannot really work out how this works....or why the formula is like this.....
Colin Law
2009-Jul-16 13:43 UTC
Re: Find_all_by and find(:all) to only select certain values for a selection box
2009/7/16 Valli <valerie.fehst-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>:> > thnx a lot for the idea, i really apreciate it!! > however it still doesn''t work correctly so anyone has an other > suggestion? >What do you mean ''it doesn''t work''? Did it generate an error? What it should do is find all the Files with mandant_id of @invoice.mandant_id. If it did not do this what did it do? If that is not what you want it to do please try asking the question again in a different way as it is not clear what you want.> well i think it could help to update the mandant_id before carrying on > with the files_id, because if not the how could the database actually > know the > new value for the mandant_id???Pardon? This makes no sense to me. Why is there a new value for the mandant_id when you are trying to find all the Files with a given mandant_id? Colin
Valli
2009-Jul-16 13:55 UTC
Re: Find_all_by and find(:all) to only select certain values for a selection box
so i want to selectioin boxes, -->one for choosing the mandant_id --> and then later having tht information in my second selection box i only want to see the files_id which correspond to tht mandant..... --> and i will choose one which i will see later in the database next to the mandant_id However in the moment i have the to selection boxes and they work fine ecxept tht the second one does''t display ONLY the files corresponding to the mandant. Does tht make any sense know?? and surry for the bad understanding....
Colin Law
2009-Jul-16 14:04 UTC
Re: Find_all_by and find(:all) to only select certain values for a selection box
2009/7/16 Valli <valerie.fehst-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>:> > so i want to selectioin boxes, > > -->one for choosing the mandant_id > --> and then later having tht information in my second selection box i > only want to see the files_id which correspond to tht mandant..... > --> and i will choose one which i will see later in the database next > to the mandant_id > > However in the moment i have the to selection boxes and they work fine > ecxept tht the second one does''t display ONLY the files corresponding > to the mandant. > > Does tht make any sense know?? > and surry for the bad understanding....In that case you may want to use AJAX to update the second selection box when the user selects from the first one. If you have not used AJAX with Rails then a bit of googling will provide numerous tutorials and guides. Colin
Valli
2009-Jul-16 14:07 UTC
Re: Find_all_by and find(:all) to only select certain values for a selection box
alright thnx a lot!! sur tht will help.... Valli
Ram
2009-Jul-17 09:23 UTC
Re: Find_all_by and find(:all) to only select certain values for a selection box
cascading select boxes search for that On Jul 16, 7:07 pm, Valli <valerie.fe...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> alright thnx a lot!! > sur tht will help.... > Valli
Sijo Kg
2009-Jul-17 11:04 UTC
Re: Find_all_by and find(:all) to only select certain values for a selection box
> because I only want to > see the foles whose mandant_id is the same like the mandant_id in > invoice.Hi File.find(:all,:conditions => {:mandant_id => Invoice.mandant_id}) Thinking that Invoice.mandant_id is an array Sijo -- Posted via http://www.ruby-forum.com/.
Valli
2009-Jul-17 11:59 UTC
Re: Find_all_by and find(:all) to only select certain values for a selection box
thank you sooo much!! tht was just what i needed for my problem!! however with each solution....there comes a new problem....so maybe could you please help me?? What I am pretending to do is this: 1) When I create a new invoice the invoice.id should put itself automatically in the place of the slip.invoice_id --> for actually finding out in which slip to put the new invoice.id I applied many find mehods: @akte = Akte.find_all_by_mandant_id(@rchng.mandant_id) @slip = Slip.find_all_by_akte_id(@akte, :conditions => {:rchng_id => ''NULL''}) --> and i donot get an error message when creating a new invoice... 2) Now tht i have found the right slip to put my invoice.id in I don''t know how to tell ruby on rails that it copies the invoice.id and pastes it into the slip.invoice_id. However I''ve tried this: --> @slip.each do |slip| slip.rchng_id = rchng.id end --> and i don''t get an error message however, the invoice.id does not appear in the slip.invoice_id So anybody has an idea of how to get this working?? thnx a lot in advance
Ar Chron
2009-Jul-17 13:22 UTC
Re: Find_all_by and find(:all) to only select certain values for a selection box
Valli wrote:> thank you sooo much!! tht was just what i needed for my problem!! > > however with each solution....there comes a new problem....so maybe > could you please help me?? > > What I am pretending to do is this: > > 1) When I create a new invoice the invoice.id should put itself > automatically in the place of the slip.invoice_id > --> for actually finding out in which slip to put the new invoice.id I > applied many find mehods: > @akte = Akte.find_all_by_mandant_id(@rchng.mandant_id) > @slip = Slip.find_all_by_akte_id(@akte, :conditions => {:rchng_id > => ''NULL''}) > --> and i donot get an error message when creating a new invoice... > > 2) Now tht i have found the right slip to put my invoice.id in I don''t > know how to tell ruby on rails that it copies the invoice.id and > pastes it into the slip.invoice_id. However I''ve tried this: > --> @slip.each do |slip| > slip.rchng_id = rchng.id > end > --> and i don''t get an error message however, the invoice.id does not > appear in the slip.invoice_id > > So anybody has an idea of how to get this working?? > thnx a lot in advanceWhat is an rchng? What''s an akte? @akte = Akte.find_all_by... implies that you want back a list, but I don''t think that''s what you want, and you don''t code for processing a list, so it probably shouldn''t be ''find_all_by...'' Same goes for @slip = Slip.find_all_by... this has the code smell of very shallow understanding. Always try to choose the most efficient, appropriate method, not a ''one-size-fits-all''... even carpenters carry more than one type of hammer. What''s a slip (ok, I can guess what that is)? Basically, how are all these things related? You won''t have an invoice.id until the invoice is saved, and there''''s nothing wrong with assigning a nil variable to another variable... do you have any validations in your models that might throw errors when trying to save a nil value? Do you spec the database to disallow nils? -- Posted via http://www.ruby-forum.com/.
Valli
2009-Jul-17 14:23 UTC
Re: Find_all_by and find(:all) to only select certain values for a selection box
oooh!! I''m very sorry I''ve completly forgotten to translate.... -->@file = File.find_all_by_mandant_id(@invoice.mandant_id) @slip = Slip.find_all_by_file_id (@file, :conditions => {:invoice_id => ''NULL''}) No, I don''t have any validations done at the moment due to the fact that they could produce errors. Well the realtions are quiet simple: 1)class Slip < ActiveRecord::Base belongs_to :invoice belongs_to :mandant 2) class Invoice < ActiveRecord::Base has_many :slips belongs_to :mandant 3) class Akte < ActiveRecord::Base belongs_to :mandant has_many :slips has_many :invoice, :through => :slips 4)class Mandant < ActiveRecord::Base has_many :files has_many :invoices has_many :slips, :through => :aktes So you said that the invoice.id must be saved before I can actually start working with it no?? -->Therefore I should locate my find methods and the loop in the controller''s def creat. Because that would mean that the invoce.id I''ve choosen earlier from my selection box has allready been saved, no?? thank you! p.s.:the shallow understanding might be because I''m quite new to ruby on rails ; )
Valli
2009-Jul-20 08:58 UTC
Re: Find_all_by and find(:all) to only select certain values for a selection box
Well found a solution to part of my last problem.... the find methods actually work know =) #Controller --> @invoice = Invoice.new @files = File.find_all_by_mandant_id(@invoice.mandant_id) @slips = Slip.find(:all, :conditions => {:invoice_id=>nil, :file_id=>@files}) However i''m still trying to find out how to OVERWRITE THE BLANK invoice_id IN MY SLIP CLASS WITH THE @invoice.id. In the moment my code looks something like this: #Cotroller -->@slips.each do |slip| invoice_id =@invoice.id end Although it doesn''t create an error message it still doesn''t overwrite the blank Slip.invoice_id...... So if anyone has a suggestion or an idea, please help me Thanks in advance....