Closed MatthewMcElwain closed 10 years ago
Your post is undefined. Do you have @post = Post.find(params[:id]) inside the show action of the Posts controller?
This is my code for posts_controller.rb:
class PostsController < ApplicationController
def new end
def create @post = Post.new(post_params)
@post.save
redirect_to @post
end
private def post_params params.require(:post).permit(:title, :text) end
def show @post = Post.find(params[:id]) end end
Could the error possibly be in routes.rb? Do I need another get statement?
The issue might be that you put the show action under post_params. I'm pretty sure the private keyword applies to every method defined under it. Try moving show up above the private and see what happens.
It works! Thanks for the help, I've been having a lot of trouble with this.
Well, now you know not to put new actions in under the private. It's kind of weird that it would get that far before hitting an error though. You'd think it would have trouble finding the action in the first place if private is a problem.
Either I screwed up something earlier in the code or I'm just missing something because I keep hitting wall after wall. I get this error message when I go to save a post:
Any help would be greatly appreciated.