Hi everyone,
I need several pages to be static but also modify when requested. I try following the railcast from Ryan at
Here what I have done!!
rails g scaffold Pages name:string permanentlink:string title:string author:string access_level:string is_published:boolean meta_description:string meta_keyword:string meta_author:string content:text
route.db get 'static/:permanentlink', :controller => 'pages', :action =>'show'
show.html.erb <p id="notice"><%= notice %></p> <p> <%= @page.title %> </p>
<p> <%= @page.content %> </p> <%= link_to 'Edit', edit_page_path(@page) %> | <%= link_to 'Back', pages_path %>
controller#show.rb def show if params[:permanentlink] @page = Page.find_by_permanentlink(params[:permanentlink]) else @page = Page.find(params[:id]) end respond_to do |format| format.html # show.html.erb format.json { render json: @page } end end
The error NoMethodError in Pages#show
Showing /home/jean/rail/wyw/app/views/pages/show.html.erb where line #3 raised:
undefined method `title' for nil:NilClass Extracted source (around line #3):
1: <p id="notice"><%= notice %></p> 2: <p> 3: <%= @page.title %> 4: </p> 5: 6: <p> Rails.root: /home/jean/rail/wyw
Application Trace | Framework Trace | Full Trace app/views/pages/show.html.erb:3:in `_app_views_pages_show_html_erb___833700274_82427120' app/controllers/pages_controller.rb:21:in `show'
Is this even a technique that his been used these day or is it to old, if still use what do i do wrong?