티스토리 뷰

Ruby&Rails/Rails

[Rails] Redirect and Flash 문법

kkd927 kkd927 2015.06.24 21:04

기본적인 문법

class PostsController < ApplicationController

def edit

@post = Post.find(params[:id])

if session[:user_id] != @post.user_id

flash[:notice] = "Sorry, you can't edit this post"

redirect_to post_path

end

end

end


대체가능한 문법

class PostsController < ApplicationController

def edit

@post = Post.find(params[:id])

if session[:user_id] != @post.user_id

redirect_to (post_path,  notice: "Sorry, you can't edit this post")

end

end

end


댓글