On 4 February 2012 15:55, Richard l. <li...@ruby-forum.com> wrote:
> hi, this is what i have now done, dont know why i didnt think if this
> earlier. However i now have the following issue.
>
> im my private_pages controller i have
>
>  def news
>
>    @post = Post.find(params[:id])
>
>    respond_to do |format|
>      format.html # show.html.erb
>      format.json { render json: @post }
>    end
>  end
>
> in my private_pages/news view i have
>
> <body id="contact">
> <h1 class="news">Bafo News</h1>
>
> <font size="3" face="arial" color="white">
>
> <table>
>  <tr>
>    <th>Title</th>
>    <th>Body</th>
>    <th></th>
>    <th></th>
>    <th></th>
>  </tr>
>
> <% @posts.each do |post| %>
>  <tr>
>    <td><%= post.title %></td>
>    <td><%= post.body %></td>
>  </tr>
> <% end %>
> </table>
>
> <br />
>
>
>
> </body>
>
>
> When i try and view the private_pages/news page i get this error message
>
> ActiveRecord::RecordNotFound in PrivatePagesController#news
>
> Couldn't find Post without an ID
>
> Any ideas?

The clue is often in the error message, it says it needs an id to find
a post.  Assuming that the line it is complaining about is
@post = Post.find(params[:id])
which you should be able to verify from the stack trace then that
suggests that params[:id] is not set.  Have a look in
log/development.log and it will tell you what parameters are being
passed in.  Also have a look at the Rails Guide on Debugging and it
will provide a number of techniques for debugging your code.  In
particular look at using ruby-debug to break into your code to inspect
data and follow the flow.  In this case if you cannot see the problem
you could break in before the offending line and see what is in
params.

Colin

-- 
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-talk@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.

Reply via email to