Obviously, there's more than one way to do this, but here's my
suggestion. Perhaps others will chime in with different suggestions
and you can pick and choose.
Assumptions: the model that contains the CSV is called UploadedCsv,
which is used to create a bunch of records named Contract.
"business logic" in general belongs in the model. So add a method to
UploadedCsv that parses your CSV. It should be responsible for
parsing the CSV and call out to a class method on Contract responsible
for creating new contracts, checking for dupes, et cetera.
I'd expose this logic to the UI by adding a lifecycle to UploadedCsv.
2 or three states: unprocessed, processed and maybe an error state.
The transition from unprocessed to processed would call the parsing
method. Lifecycle buttons are then almost automatically added by
Hobo if you have the permissions and visibility set correctly.
suggested reading: the lifecycle chapter in Hobo, and the ActiveRecord
query interface:
http://guides.rubyonrails.org/active_record_querying.html
Bryan
On Wed, Nov 21, 2012 at 7:57 AM, Drew Hamilton <
a...@awh.org> wrote:
> Hi all,
>
> First off, a very quick introduction of where I'm coming from,
> skill-level-wise: I'm a complete neophyte with both Rails and Hobo,
> although I'm familiar with Ruby. I do understand web development, MVC
> architecture, OOP, etc., and have used a variety of platforms and
> frameworks.
>
> My company needs a small internal database to keep track of contracts, and
> I'm using that as an opportunity to learn Rails. I was attracted to Hobo
> because it seems like it will eliminate a lot of the "busy work" involved in
> making an application.
>
> I did the Agility tutorial, and also followed along with my own application.
> Indeed, I was amazed at how I needed to do little more than declare my model
> to have a full application up and running. I also did some work at changing
> some of the cards for my application, just to show that I can, although I
> prefer not to do a whole lot of that until the application is more complete
> than it is.
>
> Where I'm stuck now is that after the tutorial, I have an app that allows
> users to enter and view data, but I don't have a really good understanding
> of how to make it do things programmatically.
>
> In my specific case, the contract data in my application really only needs
> to be *viewed*; the data itself should be uploaded once per month from a CSV
> file and then cleaned up, have the uploader notified of problem rows, etc.
> I used Paperclip and made a model that would take the raw CSV files, and I
> also made a model to hold the actual data from the files.
>
> Parsing the CSV isn't the problem; I'm sure there are many Ruby libraries
> that can help. What I don't know is
>
> - If I wanted to make a link in the "uploaded csv file" page that, when
> clicked would run code, how do I make that link? And where does the code
> itself go?
> - How do I access the data (not the CSV file; I mean how do I make new
> records; how do I search existing records, etc.) from that code?
>
> I'm certainly not asking anyone to do my work for me; just hoping that
> someone could give me a link that I can read, or a link to a hobo-based
> project with public source code, etc. that would help point me in the right
> direction.
>
> Thanks!
>
> - Drew
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Hobo Users" group.
> To view this discussion on the web visit
>
https://groups.google.com/d/msg/hobousers/-/zvwqiZ7JjuMJ.
> To post to this group, send email to
hobo...@googlegroups.com.
> To unsubscribe from this group, send email to
>
hobousers+...@googlegroups.com.
> For more options, visit this group at
>
http://groups.google.com/group/hobousers?hl=en.