ruby - Rails 3 Routes: How do you show a nested page? -


i show first page lesson when click on show link

here have:

lesson index:

<%= link_to 'show', lesson_page_path(lesson)%><br /> 

pages controller

def show   @lesson = lesson.find(params[:id])   @first_page = @lesson.pages.first    respond_to |format|     format.html # show.html.erb     format.json { render json: @page }   end end 

routes

resources :lessons   resources :pages end 

i getting error

no route matches {:action=>"show", :controller=>"pages", :lesson_id=># lesson id: 1, title: ...

how can url when click on show link:

/lessons//pages/1

if you're nesting that, need link both page , lesson:

lesson_page_path(lesson, page) 

if want first one, define route:

get '/lesson/:lesson_id/page_one', :to => "pages#show" 

Comments

Popular posts from this blog

delphi - How to convert bitmaps to video? -

jasper reports - Fixed header in Excel using JasperReports -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -