0

I'm making a website with a simple form on the homepage. When the user submits the form, the application crawls a website and then presents the results on a new page.

  • Domain.com has the search form (:method => "get")
  • Domain.com/search/xxxxxx has the results of the search.

I'm having trouble thinking about Models and Controllers when I'm not working with obvious objects like Users, Posts, Threads, or ShoppingCart.

What's the Rails way of organizing such an application?

John Topley
  • 113,588
  • 46
  • 195
  • 237
danneu
  • 9,244
  • 3
  • 35
  • 63
  • Not using Rails? (Seriously, it sounds like Rails would kind of be overkill for this... :P) – Amber Feb 23 '11 at 20:12

3 Answers3

4

Try using sinatra

Your site should look like this. Rails is too heavy for your requirements.

get '/' do
   erb :form, layout => :layout
end

get '/search/:key_word' do
 # use params[:key_word] to do what u want
end
Zimbabao
  • 8,150
  • 3
  • 29
  • 36
1

You do not need to use a model for every controller. In this case i would use a single SearchController

rails g controller Search index

add this to the routes:

match '/search/:keyword' => 'search#index'
root :to => 'search#index'

and in your controller you can write

class SearchController

  def index
    if params[:keyword]
      # search for the keyword ...

    else
      # render the search-form
    end
  end
end

So it is pretty easy to do in rails. Using rails in a case like this is useful if you have other parts of the site that need more functionality. Also working with the views is maybe easier. Otherwise it is now possible in rails 3 to load only the parts that you really need. So in this case you would want to not load ActiveRecord.

An alternative approach is to use something simpler like sinatra.

Community
  • 1
  • 1
nathanvda
  • 49,707
  • 13
  • 117
  • 139
0

Just use one controller, Search, and a model Searches. Then you can store every search in the DB and allow users to retrieve them, or create permanent urls for searches. You could use Nokogiri to do the web crawling.

Tim
  • 88
  • 5