Manipulating a Rails site from Ruby code

8 views
Skip to first unread message

Craig Read

unread,
Dec 12, 2011, 9:59:09 PM12/12/11
to Rails Oceania

Hi Everyone,

I have a Rails app that I intend to seed with data generated by a log parsing program (written in a later version of Ruby). I want some basic checking to make sure I'm not duplicating reference data, etc.

Should I be creating custom find / exists actions in the relevant controllers just for this, or is there a better way of doing this?

Cheers,

--
Craig Read
@Catharz
https://github.com/Catharz
http://code.google.com/p/bsss

Nicholas Faiz

unread,
Dec 13, 2011, 2:39:10 AM12/13/11
to rails-...@googlegroups.com
Two ideas.

1 - just rely on your validations to ensure that you have unique data.

2 - Push all of your data into a set before saving it to ensure uniqueness (though, this won't scale well, but if your data is small it might not be an issue).

Cheers,
Nicholas

Oleg Ivanov

unread,
Dec 13, 2011, 6:43:06 AM12/13/11
to Ruby or Rails Oceania
What kind of data are you working with? If it's not something
involving uniqueness tests on large texts/binaries, then I'd say it's
a valid use case for validations and unique indices in the database
(if you're using a relational one).

Craig Read

unread,
Dec 13, 2011, 5:02:53 PM12/13/11
to rails-...@googlegroups.com, Ruby or Rails Oceania
Thanks for the responses Nicholas and Oleg.

I have unique constraints in the database, but was wondering there might be a "simple" (or "common") pattern for this. A fairly "dumb" script will be performing the upload, and I'm hoping to avoid implementing much in the way of exception handling.

I'm currently working on parsing XML from the server. The list of items (that I need to be unique) shouldn't be too large to just retrieve and compare against before uploading to the server.

I was considering creating actions to check the pre-existence of items, but it doesn't feel right to create actions for something a user will never do directly, and what will hopefully be run rarely.

Cheers,

> --
> You received this message because you are subscribed to the Google Groups "Ruby or Rails Oceania" group.
> To post to this group, send email to rails-...@googlegroups.com.
> To unsubscribe from this group, send email to rails-oceani...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/rails-oceania?hl=en.
>

Oleg Ivanov

unread,
Dec 13, 2011, 6:09:49 PM12/13/11
to Ruby or Rails Oceania
If you want to keep your client dumb, why not just let your server
code validate uniqueness of your data, and skip any non-unique
records, if you don't care much about them? It would allow the client
to concentrate on the single task of feeding the data into the server,
and let the server decide what to keep.

PS: you mentioned doing "parsing XML from the server" - if you're
using Rails on the server, and it's restful - have you considered
leveraging ActiveResource for your client? I personally find it to be
the easiest and best match for Rails-bound interactions in many cases,
as it basically removes the need for 90% of integration work and code.

Craig Read

unread,
Dec 13, 2011, 11:19:54 PM12/13/11
to rails-...@googlegroups.com, Ruby or Rails Oceania
Thanks Oleg,

I hadn't considered using ActiveResource (still very much a newbie at Rails). I had a look at it over lunch though, and that's exactly how I'll do it.

Thanks for the help!

Cheers,

Reply all
Reply to author
Forward
0 new messages