Saturday, 15 August 2015

Rails 3 route for subpage -



Rails 3 route for subpage -

i have little problem in rails 3 routing

i have controller page showing pages like

example.com/some_page_title

but need set there subpage in current page

example.com/some_page_title/some_subpage_title

my route looks now:

match ':title' => 'page#show'

but show subpage? recognize subpage fild parent_id true has subpage false main page. have set subpages other controller or in other table of database?

what if want alter subpage normal page, remove parent_id , done.

you try:

match :parent_title/:title => "pages#show"

assuming:

class page has_many :subpages, :class_name => "page" end

in controller

def show if params[:parent_title].present? parent = page.find_by_title params[:parent_title] @page = parent.subpages.find_by_title params[:title] if parent.present? end end

ruby-on-rails ruby-on-rails-3 controller routes

No comments:

Post a Comment