Newbie needs your help :D I want to figure out how to save parsed data from external api to database

37 views
Skip to first unread message

George Stoumpos

unread,
Oct 5, 2016, 2:51:56 PM10/5/16
to Ruby on Rails: Talk
Hi there!

I need your help

I need to figure out a way to save parsed data in my apps database.

Using nokogiri and open-uri I've managed to create an Array object with several hashes. All I want to do next is to save each hash object as a database entry.
I have a controller with all the CRUD actions, but I cant find a way to save each hash in my db. 

Somehow I am frustrated and I cant seem to figure this out.

Thank you in advance

Hassan Schroeder

unread,
Oct 5, 2016, 3:26:29 PM10/5/16
to rubyonrails-talk
On Wed, Oct 5, 2016 at 11:51 AM, George Stoumpos <sto...@gmail.com> wrote:

> Using nokogiri and open-uri I've managed to create an Array object with
> several hashes. All I want to do next is to save each hash object as a
> database entry.
> I have a controller with all the CRUD actions, but I cant find a way to save
> each hash in my db.

What exactly are you having a problem with? Storing a single hash,
or storing multiple hashes during a single request, or ?

Do you have some code to show where you're blocked?

--
Hassan Schroeder ------------------------ hassan.s...@gmail.com
http://about.me/hassanschroeder
twitter: @hassan
Consulting Availability : Silicon Valley or remote

George Stoumpos

unread,
Oct 5, 2016, 3:33:41 PM10/5/16
to Ruby on Rails: Talk
>What exactly are you having a problem with? Storing a single hash,
>or storing multiple hashes during a single request, or ?

>Do you have some code to show where you're blocked?

look for the profnews action

 

Hassan Schroeder

unread,
Oct 5, 2016, 3:58:05 PM10/5/16
to rubyonrails-talk
On Wed, Oct 5, 2016 at 12:33 PM, George Stoumpos <sto...@gmail.com> wrote:

> here's my code http://pastebin.com/X4c40WYn
> look for the profnews action

So what's not happening that you expect? Or happening that you
don't expect?

I would probably move all that build logic into a service object to
make it easier to test, but regardless, do you have a failing test for
this?

If not, creating one would be a good place to start :-)

Colin Law

unread,
Oct 5, 2016, 4:01:37 PM10/5/16
to Ruby on Rails: Talk
Have a look at the rails guide on debugging [1] for suggestions on how
to work out what is/is not happening in your code

Colin

[1] http://guides.rubyonrails.org/debugging_rails_applications.html

George Stoumpos

unread,
Oct 6, 2016, 10:00:19 AM10/6/16
to Ruby on Rails: Talk
Thank you everyone for your efford to help me :D
It seems there was a problem with my routes, I managed to fix what I was supposed to do!

Thank you again!

Cheers!
Reply all
Reply to author
Forward
0 new messages