1

I wrote a small ruby script that generates an array like the one below:

{:title=>"Lorem ipsum",
 :category=>["Lorem ipsum"],
 :items=>
  ["Lorem ipsum",
   "Lorem ipsum",
   "Lorem ipsum"],
 :process=>
  ["Sed ut perspiciatis unde omnis iste natus error."]}

How can I run that script in order to save the output into my rails database?

3
  • What Models do you have in your app? are these items stored under a different model? Commented Jan 16, 2011 at 18:48
  • @adam: I have 3 models. Model "A" => Title and Process Model "B" => Items Model "C" => Category Commented Jan 16, 2011 at 18:51
  • 1
    I think you mean "hash", not array. you say model A holds title and process, but then you use an array for process. On the other hand, what's the nature of the problem, this seems pretty straighforward AR usage, did you peruse the Rails guides? Commented Jan 16, 2011 at 18:59

1 Answer 1

1

With a bit of guessing... you can write this is a rake task:

WeDontKnowWhichModelHere.create!({
 :title => "Lorem ipsum",
 :categories => [Category.new(:name => "Lorem ipsum"), ...],
 :items => [Item.new(:name => "Lorem ipsum"), ...],
 :processes => [Process.new(:name => "Sed ut perspiciatis unde omnis iste natus error")],
})
Sign up to request clarification or add additional context in comments.

2 Comments

Where in the project should I call my script.rb in order to gather the output? Thank you
@antonio. If this is a code outside the request cycle, you can write a rake task: stackoverflow.com/questions/876396/…, railscasts.com/episodes/66-custom-rake-tasks

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.