launchscout / nku

NKU Class Spring
5 stars 14 forks source link

Tutorial - 5.7: Showing Posts #8

Closed MatthewMcElwain closed 10 years ago

MatthewMcElwain commented 10 years ago

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:

capture 3

Any help would be greatly appreciated.

jaimerump commented 10 years ago

Your post is undefined. Do you have @post = Post.find(params[:id]) inside the show action of the Posts controller?

MatthewMcElwain commented 10 years ago

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?

jaimerump commented 10 years ago

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.

MatthewMcElwain commented 10 years ago

It works! Thanks for the help, I've been having a lot of trouble with this.

jaimerump commented 10 years ago

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.