# Parsing data and create records when app starts

**URL:** <https://www.ruby-forum.com/t/parsing-data-and-create-records-when-app-starts/222563>\
**Category:** Rails\
**Created:** [September 1, 2012, 7:39pm UTC](https://www.ruby-forum.com/t/parsing-data-and-create-records-when-app-starts/222563 "2012-09-01T19:39:23Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![aris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/258eb7/32.png) [@aris](https://www.ruby-forum.com/u/aris)\
**Post date:** [September 1, 2012, 7:39pm UTC](https://www.ruby-forum.com/t/parsing-data-and-create-records-when-app-starts/222563/1 "2012-09-01T19:39:23Z")

</div>

Hello,  
I’m a newbie and would be appreciated for any help.

So that’s the situation: I try to build a simple rails app which will  
give users an opportunity to manage a list of some product. But except  
creating by user, some products list should be loaded into the view when  
app starts. This list is produced by parsing information from a  
web-site. I’ve already write a ruby script which collects the data and  
push it into “Product” object.

And now, how to implement that in rails app enviroment?  
Here I have “Product” model with the required parameters, but where I  
should implement initial creating these products (when app starts) to  
see them at the view?  
Something like that:

=========== some\_file.rb(model?conroller?) ===========

def pull\_data(WEBSITE\_URL)  
…

# parsing data into initial\_products array

…

# creating new records according to the parsed objects

initial\_products.each do |p|  
Product.new(p.field1, p.field2, …)  
end  
…  
end

============== product.rb ==============

class Product \< ActiveRecord::Base  
attr\_accessible %list of parameters%  
end

---

<div class="post-metadata">

**Author:** ![enki](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/b5ac83/32.png) [@enki](https://www.ruby-forum.com/u/enki)\
**Post date:** [September 1, 2012, 11:34pm UTC](https://www.ruby-forum.com/t/parsing-data-and-create-records-when-app-starts/222563/2 "2012-09-01T23:34:29Z")

</div>

> products list should be loaded into the view when  
> app starts.

In Rails, apps don’t start. Instead, web browsers send requests to  
urls, which your app then directs to the proper controller and action.  
So I would start by reading the Rails Guide about routing to figure out  
how to write simple routes. Then you can route a chosen url to a  
certain controller in your app and to a certain action in that  
controller. The action can then provide the data, i.e. Products, that  
the view associated with that action will display.

If that doesn’t make any sense, you are going to have to read a rails  
tutorial and construct a sample app to learn the basics of how rails  
works.

---

<div class="post-metadata">

**Author:** ![enki](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/b5ac83/32.png) [@enki](https://www.ruby-forum.com/u/enki)\
**Post date:** [September 2, 2012, 12:35am UTC](https://www.ruby-forum.com/t/parsing-data-and-create-records-when-app-starts/222563/3 "2012-09-02T00:35:55Z")

</div>

Hmm, I think I get it. Thanks.

And now it works just as I planned.
