Sunday, December 9, 2012

Re: [Rails] Need some super-noob help with some concepts

On 8 December 2012 02:57, Jim Stolzenbach <jkstolzenbach@gmail.com> wrote:
> Hello all! I'm new to actually building anything with these little
> fragments of programming knowledge that I cobbled together, so I'm hoping
> someone can give me a push in the right direction.
>
> I'm working on building a 'utility' rails site that will only be used by
> myself and one or two coworkers. I'm not concerned with security (it will
> be a local webserver only), appearance, etc. I just need one thing to work.
> The plan is this:
>
> I have remote jobsites that will report back to our server via a small ftp
> file. For now it will just send us their WAN IP, but I plan on expanding
> this once I figure out the overall structure of what the heck I'm trying to
> do. :) I want to be able to go to the local Rails webserver and see a list
> of all our jobsites with a list of their WAN IPs and last updated times.
>
> So... I have the FTP side working. I have the rudimentary Rails 'site'
> working, and I can manually enter jobsite info at the localhost:3000/sites
> URL. I need to automate the process of parsing each FTP file and adding it
> to the database. The parsing I can work out, but I am clueless on how to
> even begin updating this 'app' from a script that is 'outside' of the Rails
> app...if that makes sense.
>
> I can run a script that parses the FTP file, but what approach do I take to
> get the parsed info INTO the database?
>
> There are probably 100 ways to do this and I know 0 of them. :)

You could run a Rake task to update the db. The proper way to do this
would be to write a rake task, but the easiest way to get going would
be to use the provided rake task db:seed. This runs the file
db/seeds.rb in the context of the application, so that all the
ActiveRecord stuff is automatically available. To run the rake task
you just
cd /path/to/rails/application
rake db:seed
or if you want it to run on the production db
RAILS_ENV=production rake db:seed
which could be run from a cron task or whatever is appropriate.

So all you need do is to put your code in db/seeds.rb and you will be
up and running.

Colin

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate