NoMethodError on section 5.7 of Rails Guide

前端 未结 2 1715
萌比男神i
萌比男神i 2021-01-25 17:48

I\'m following the Getting Started tutorial for Rails 4.0.0 located here: http://guides.rubyonrails.org/getting_started.html

I\'m at the point in section 5.7 where I\'m

2条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-25 18:45

    Just write down show method after create method, as your show method is below the keyword private it is taking private as a Access Modifier and hence can't access directly through browser

    class PostsController < ApplicationController
      def new
      end
    
      def create
        @post = Post.new(post_params)    
        @post.save
        redirect_to @post
      end
    
      def show
        @post = Post.find(params[:id])
      end
    
      private
        def post_params
          params.require(:post).permit(:title, :text)
        end           
    end
    

提交回复
热议问题