RailsCasts Pro episodes are now free!

Learn more or hide this

Recent Comments

Avatar

Super website with a great sharing and amazing stories is ur web.. please keep doing what u do now.. thanks to you, It's a great sharing and really informative.. will keep following ur web. thanks to you and ur great website.

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.

Avatar

Building on your response, I replaced Ryan's with_last_state with this MAX(id) solution:

ruby
class OrderEvent
  def self.with_last_state state
    where state: state, id: select('MAX(id)').group(:order_id)
  end
end
Avatar

Thank you so much, great advice !

Avatar

Perfect for my preference. I love being super emotional and over dramatic and in this situation, I sprung to my keyboard and started to type in and got right to adding to my property.

Avatar

Thank you for the information! very good article!

Avatar

Hi Luke,

I was wondering, would I replace the word column with my div's class if I was to use div's instead of tables?

Avatar

Cool content !very pleased with the author

Avatar

find_by will return only one row, while find_all_by (not find_by_all) returns all of found records.
But now find_all_by is deprecated and you need to use where. Example:

Ruby
Example.find_all_by_published(true)
# should be replaced with 
Example.where(published: true)
Avatar

Thanks, that's reaaly useful. Will apply.

Avatar

Thanks have been given the opportunity to comment. Hopefully what you provided is useful for all those who need them. Visit my website if you want to know more about:

Avatar

Thank you for sharing videos about rails. Good job!

Avatar

I enjoy the subject you are talking about. It very interesting! Thanks for sharing!

Avatar

This is really interesting information for me. Thanks for sharing!

Avatar

Great feature I will use it! thanks

Avatar

I had a very similar problem. Thank you for posting a solution, this does not happen often on the internet :)

Avatar

Lets say I have News and Blog Posts and I have feed for both of these. Do you recommend it from SEO perspective. Should I try to provide a single feed or separate feed depending on the controller. As shown in this railscast. Or have a separate FeedController and have one feed?

Avatar

Thanks a lot, it has clear a lots of thing.

Avatar

Perfect website, thanks for sharing.

Avatar

Thanks for sharing information, good advise.

Avatar

I really wanted to send a small word to say thanks to you for the fantastic points you are writing on this site.

Avatar

Thanks for the tips and guide. It is very useful tips.

Avatar

Interesting post. I Have Been wondering about this issue, so thanks for posting.

Avatar

was looking for this information, thanks to the author of the post, I am glad to join your community!

Avatar

Agree with your opinion, thanks

Avatar

This is the type of information I’ve long been trying to find. Thank you for writing this information.

Avatar

Thanks for sharing information, good advise.

Avatar

Thanks for the tips and guide. It is very useful tips.