Yes that does help quite a bit actually. What used to be about as
clear as mud, is now about as clear as milk. I feel I'm close to
seeing the solution, but still can't quite see past the obstruction
(err abstraction).
Cool!
I'm still a bit of a novice with Rails, so I'm still struggling a bit
on how to map out the routes and such. It would help to have a
concrete example showing such things as the map.resources, a basic
controller action for having a "Search" resource, etc. Could a
"Search" resource be used generically to query any ActiveRecord
subclasses?
Sorry, you're right: Show! Don't Tell!
'ruby script/generate scaffold_resource Model' will generated a lot of stuff.
If you need CRUD actions on a model mapped to a 'real' table in your
database, don't change anything! Notice the map.resources :model added
to your routes.rb. It has generated for you the routes you need.
Maybe you just want to tweak your controller, with a:
before_filter :admin_authorize, :only => [:delete,:update]
You'll have all the actions and views you need to CRUD your table. See
your app/views/model/*.rhtml for details.
What about the search resource? It's a little more complicated (hey!
it's not a big thing! It's Rails, not Struts!)...
So we want to have an action mapped to a route like:
/search/posts/:publish_date_from/:publish_date_to/
First, 'ruby script/generate scaffold_resource Search' will do for you
the half of work. But you still need to tweak the show action:
def show
@results = Post.find_by_publish_date_from_and_publish_date_to(params[:publish_date_from],params[:publish_date_to])
respond_to do |format|
format.html #do fancy stuff with @results in your view
format.xml {}
end
end
Remove the DELETE and UPGRADE actions in this example, since you
won't need it. The INDEX one will be used to show a form for your customers
to enter those informations (params[:publish_date_from],params[:publish_date_to]).
What about the routes? Remove the map.resources :searches since it's not
the type of routes you need. Instead, you could do something like:
map.search '/search/posts/:publish_date_from/:publish_date_to',
:controller => 'searches',
:action => 'show',
:conditions => {:method => :get}
The search resource is actually a bad example since you only need a GET.
For example, in a auth_admins resource (wich will CRUD cookies for
authorizations), /logout is mapped to the destroy action:
def destroy
session[:id] = nil
respond_to do |format|
format.html { redirect_to auth_admins_url }
format.xml { head :ok }
end
end
map.cabinet_logout 'logout', :controller => 'auth_cabinets', :action
=> 'destroy', :conditions => {:method => :put}
Be careful to respect the ' and :, since conventions for them in the
routes module suck (erf, should I say: I don't understand them?).
Actually, I'm not sure about the pluralization of 'search'. Just add in
your config/environment.rb:
Inflector.inflections do |inflect|
inflect.irregular 'search', 'searches'
end
Hope I'm clear,