Coder Social home page Coder Social logo

Comments (5)

jaimerump avatar jaimerump commented on September 1, 2024

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

from nku.

MatthewMcElwain avatar MatthewMcElwain commented on September 1, 2024

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?

from nku.

jaimerump avatar jaimerump commented on September 1, 2024

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.

from nku.

MatthewMcElwain avatar MatthewMcElwain commented on September 1, 2024

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

from nku.

jaimerump avatar jaimerump commented on September 1, 2024

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.

from nku.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.