On 25 January 2012 08:36, amvis <[email protected]> wrote: > can i use like this.. > > myrake file > > task :my_task => [:environment] do > rd=MofobirakesController.new > rd.index > end > > Controller file > > > class MofobirakesController < ApplicationController > def index > puts "hai rails3" > end > end > > what is the difference in that way to do in controller and in model..?
The difference is that controller actions are intended to be run in response to http requests. To try and run one as part of a rake action does not make logical sense. You ask at the top whether it would work, I have no idea whether it would work or not and it is irrelevant because there is no sense in doing it. If you have code that is common between a controller action and a rake task then the code should not be in a controller action. Move it to a model or into lib and call it from the controller and the rake task. What does the code that you want to call do? Colin > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To view this discussion on the web visit > https://groups.google.com/d/msg/rubyonrails-talk/-/bP0dF4CYiOcJ. > > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. -- gplus.to/clanlaw -- 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 [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

