브라우저 콘솔 또는 페이지에 메시지를 인쇄하여 각 메서드가 호출 될 때 정확히 볼 수 있습니다. 아무것도 인쇄되고 있지 않으며 작동하는 해결책을 찾지 못했습니다. 플래시 메시지를 사용해 보았지만 제대로 작동하지 않았습니다. 나는 레일즈를 배우려고하고 있는데, 정확히 무엇이 호출되는지를보고 싶습니다. 예를 들어 create가 호출되면 "Create was called!"라는 메시지를보고 싶습니다. 나는 이것을 시도했다 :메서드가 호출 될 때 콘솔에 출력 하시겠습니까?
class PostsController < ApplicationController
# only index, show, new, and edit pages will have views
# create, update, and destroy will do some kind of work and then redirect
# instance variables are visible in our view files
def index
@posts = Post.all
end
def show
# find the post and find the id that was passed into the url
@post = Post.find(params[:id])
flash[:success] = "SHOW WAS CALLED IN FLASH"
puts "SHOW METHOD WAS CALLED!"
end
def new
@post = Post.new
end
def create
@post = Post.new(params[:post])
if @post.save
redirect_to(posts_path, :notice => "Your post was saved!")
else
render "new"
end
end
def edit
puts "<p>EDIT METHOD WAS CALLED!</p>"
@post = Post.find(params[:id])
end
def update
puts "UPDATE METHOD WAS CALLED!"
@post = Post.find(params[:id])
if @post.update_attributes(params[:post])
redirect_to posts_path, :notice => "Your post has been saved."
else
render "edit"
end
end
def destroy
puts "DESTROY METHOD WAS CALLED!"
@post = Post.find(params[:id])
@post.destroy
redirect_to(posts_path, :notice => "Post deleted")
end
end