RailsCasts Pro episodes are now free!

Learn more or hide this

Ned Holt's Profile

GitHub User: nedholt

Site: http://tiny.cc/8mqdky

Comments by Ned Holt

Avatar

I was having problems with scope_out.

Avatar

You can also store the model in memcached using cache_fu. (no DB hit)

Class User
acts_as_cached
after_save expire_cache
end

User.get_cache(id)
User.reset_cache(id)

Avatar

My question is though, now that I'm accessing the nested tags resource under posts, should I be hitting the Tags controller still? Or should I setup some other controller to handle the nested nature of tags at this point? Otherwise I have to build additional logic into the Tags controller. This can be done of course, but is this the common way of handling nested routes and resources? The code I have in the index action for the Tags controller is as follows:

def index
if params[:post_id] && @post = Post.find_by_id(params[:post_id])
@tags = Post.find_by_id(params[:post_id]).tags
else
@tags = Tag.order(:name)
end
respond_to do |format|
format.html
format.json {render json: @tags.tokens(params[:q]) }
end
end

Avatar

Routes for the users resource in routes.rb. also defined as

{Rails.application.routes.draw do
resources :users, only: [:index, :show, :update]

end}

Avatar

The documentation says that the :find keywords “may include the :conditions, :joins, :include, :offset, :limit, and :readonly options”. Note that this does not mean that only those options are supported. :sort also works like it should, for example.