hi all, i''m certain this is a basic question, but i haven''t managed to find an answer just yet! i''ve got a method that is currently in my view .rhtml file, but i would like to place it in my controller because i get the feeling that would be the more tikanga way. but so far i haven''t been able to pass a variable from the view to the method in the controller! someone show me the way please :). and just quickly - since i think this is probably a basic question as well: are there ssh/telnet commands that can rename, or delete a controller and its view, model and helpers etc in one go? i''ve renamed by hand once and having to open all the files and change their class names takes time. also, if i wanted to move a rails app from one server to another, could i just download all the files and folders and then re-upload them to a new server with the website intact? a bunch of unrelated questions, i know, but better to put them all here than to fill the airwaves with all my little q''s. :) many thanks luke
| >i''ve got a method that is currently in my view .rhtml file, but i would like to | >place it in my controller because i get the feeling that would be the more | >tikanga way. but so far i haven''t been able to pass a variable from the view to | >the method in the controller! someone show me the way please :). | > | what exactly are you trying to pass back and what does the method do? i''ve got the following method that is currently in the .rhtml view file: def format_time(seconds) arr = [ [''second'', [3600] ], [''hour'', [24] ], [''day'', [31, 7] ], [''week'', nil ], ] t = seconds aix = 0 while (lim = arr[aix][1]) ## ternary operator cond ? true : false (t >= lim[0]) ? t /= lim[-1] : break aix += 1 end ## % is a method of the String class (like sprintf) ''%4d %s%s'' % [t, arr[aix][0], (t == 1) ? '''' : ''s''] end i can send a variable to format_time() by writing ''format_time(55465465)'', but i would like to move that function to the controller, and pass a variable from the view to format_time() in the controller. thanks luke
luke wrote:>hi all, > >i''m certain this is a basic question, but i haven''t managed to find an answer >just yet! > >i''ve got a method that is currently in my view .rhtml file, but i would like to >place it in my controller because i get the feeling that would be the more >tikanga way. but so far i haven''t been able to pass a variable from the view to >the method in the controller! someone show me the way please :). > > >what exactly are you trying to pass back and what does the method do?>also, if i wanted to move a rails app from one server to another, could i just >download all the files and folders and then re-upload them to a new server with >the website intact? > > >you should be able to tar the entire rails directory and more it to a new machine... then adjust database.yaml etc as needed assuming any gems you require are on the new machine _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
On 7/9/05, luke <lduncalfe-ZKwmMI9HCDA@public.gmane.org> wrote:> | >i''ve got a method that is currently in my view .rhtml file, but i would like > to > | >place it in my controller because i get the feeling that would be the more > | >tikanga way. but so far i haven''t been able to pass a variable from the view > to > | >the method in the controller! someone show me the way please :). > | > > | what exactly are you trying to pass back and what does the method do? > > i''ve got the following method that is currently in the .rhtml view file: > > def format_time(seconds) > arr = [ [''second'', [3600] ], > [''hour'', [24] ], > [''day'', [31, 7] ], > [''week'', nil ], > ] > t = seconds > aix = 0 > while (lim = arr[aix][1]) > ## ternary operator cond ? true : false > (t >= lim[0]) ? t /= lim[-1] : break > aix += 1 > end > ## % is a method of the String class (like sprintf) > ''%4d %s%s'' % [t, arr[aix][0], (t == 1) ? '''' : ''s''] > end > > i can send a variable to format_time() by writing ''format_time(55465465)'', but > i would like to move that function to the controller, and pass a variable from > the view to format_time() in the controller.It seems to me that this is the exact use case for an helper ... see here for more info on helpers http://wiki.rubyonrails.com/rails/show/UnderstandingHelpers Jean