Thanks Matt.
I see a lot of named_scope question. I have just started with rails and have created a few paages manually without scaffolding, but producing the same results. That is where i stand with rails. I am not clear on the named_scope. Sorry for this silly question. What is this named_scope. You have provided a very good example, but still.. I'm sure all gurus are aware of it, i see it recommended by several ppl. thanks in advance. radha Matt Jones wrote: > On Jun 28, 10:36�pm, RailsFan Radha <li...@ruby-forum.com> wrote: >> Active/inactive are set via status column in category table. >> where status='A' >> >> since the url shows up in the url bar, the user can simply type in a >> different category_id and view the record, even if status = 'I' >> but, i don't want the user to modify the url and view the category where >> status <> 'A' >> In short, the users get to view only status='A' >> > > If you're doing this a lot, you should add it as a scope to the > Category model: > > class Category < ActiveRecord::Base > named_scope :active, :conditions => { :status => 'A' } > end > > Then your controller action could be: > > def show > @category = Category.active.find(params[:category_id]) > end > > which will throw a RecordNotFound if the supplied ID isn't also > active. > > BTW, the use of :category_id in the above sample is odd - if you're in > CategoriesController and have the standard routing, (/categories/:id) > the parameter will be named :id. :category_id would be used if, for > instance, you had a nested route to a Post model: > > /categories/:category_id/posts > /categories/:category_id/posts/new > > etc. > > --Matt Jones -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-t...@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.