티스토리 뷰

Ruby&Rails/Rails

[Rails] Redirect and Flash 문법

덕's 머니스토리 2015. 6. 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


반응형
댓글
반응형
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2026/07   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함