Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Rake task generate in ROR

I am new in ROR and im using version Ruby 1.9.3 & Rails 3.1.0.

I want to generate rake task. How to generate rake take?

i am using below code for generate rake task in commend prompt.

rails generate task permission my_task1 my_task2

But every time give message "Could not find generator task"

Please help.

like image 809
Abid Hussain Avatar asked Dec 17 '13 12:12

Abid Hussain


People also ask

What is rake task in rails?

Rake is a popular task runner for Ruby and Rails applications. For example, Rails provides the predefined Rake tasks for creating databases, running migrations, and performing tests. You can also create custom tasks to automate specific actions - run code analysis tools, backup databases, and so on.

How do I list a rake task?

You can get a list of Rake tasks available to you, which will often depend on your current directory, by typing rake --tasks . Each task has a description, and should help you find the thing you need.


2 Answers

You create a new file in lib/tasks like lib/tasks/your_task.rake.

You add a new task to that file:

namespace :my_app do
  desc "a new task to be executed"
  task :my_task do
    puts "hello rake"
  end
end

This would be called like rake my_app:my_task


Update

The task generator was added in Rails 3.2.0

like image 65
phoet Avatar answered Nov 12 '22 01:11

phoet


Haven't found the reason for this question why rails generating error. So i have done bit searching somewhere else and found this. May this help. Use this instead -

      bundle exec rails g task permission my_task1 my_task2

Rails is not able to find task so this is a work around to get you going.

src - [https://railsguides.net/how-to-generate-rake-task/]

like image 28
Karamdeep Singh Avatar answered Nov 12 '22 01:11

Karamdeep Singh