Skip to content
This repository has been archived by the owner on Sep 2, 2022. It is now read-only.

Tutorial - 5.7: Showing Posts #8

Closed
MatthewMcElwain opened this issue Jan 23, 2014 · 5 comments
Closed

Tutorial - 5.7: Showing Posts #8

MatthewMcElwain opened this issue Jan 23, 2014 · 5 comments

Comments

@MatthewMcElwain
Copy link

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
Copy link

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

@MatthewMcElwain
Copy link
Author

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
Copy link

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
Copy link
Author

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

@jaimerump
Copy link

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants