I'm relatively new to Rails. I'm working on an app to search craigslist (simply for personal use). I have an import method that takes a category and state or city, then loads the corresponding RSS feed(s) from craigslist.
Currently I have two models, Import and Post. I never really intended the Import model to have a corresponding table, but just a .rb file to store things related to the import method. I mean to have an import method load an RSS feed and create a Post for every item. Then I would be able to search Posts as usual. But I've ran into trouble...
My model begins with an array of every craigslist category, of every state and then all of the cities in one array.
class Import < ActiveRecord::Base require 'rss' require 'open-uri' categories = ['ccc', 'act', 'ats', 'kid', 'wrg', 'res'] # real array is substantially longer alabama = ['auburn', 'bham', 'dothan', 'shoals', 'gadsden', 'huntsville', 'mobile', 'montgomery', 'tuscaloosa'] alaska = ['anchorage', 'fairbanks', 'kenai', 'juneau'] # ... goes on for all 50 states states = [alabama, alaska, arizona] # goes on for all 50 zones = states.flatten
Then my import method begins. I start by checking that the given category exists:
def self.import(category, zone, state) if categories.include?(category)
But when I enter "Import.import('web', 'dallas')" in the Rails console, I get the following:
NameError: undefined local variable or method `categories' for #<Class:0x007f8c6e6e50d0>
I acknowledge that I'm probably doing all sorts of things wrong. Can anyone rip this apart and tell me how I should go about it? Where should I put these arrays if not in the model, and would it be better to persist them to the database?
Thanks for taking the time.