0

Project is the model name and I want to do something like:

Project.create(:name => 'projectname', :identifier => 'projectidentifier')

This should be done in the terminal through a ruby script. I am not going to use rails console to create it nor use seeds.rb in a db file to migrate this as rake db:seed.

Can someone help. Thanks

1
  • You still gonna need to load rails app. Commented Dec 14, 2012 at 8:02

2 Answers 2

1

The easiest way would be using rails runner (which essentially loads rails):

rails runner your_script.rb

The line of code would be a content of that script.

Sign up to request clarification or add additional context in comments.

Comments

1

What about a rake task?

on lib/tasks, create a file named data.rake, and the content:

namespace :data
  desc "Create project data"
  task create_project_data: :environment do
    Project.create(name: 'projectname', identifier: 'projectidentifier')
  end
end

And you can run it as any rake task

rake data:create_project_data

And it will also appear when you list your rake tasks

rake -T

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.