2013-08-30 1 views
-1

대신에 (내가 레일에 의해 생성 된 생각하는) 다음을 사용하는 game.errors : 나는 플래시 메시지로 오류를 넣을사용하여 플래시 메시지가

def create 
    @game = current_user.games.create(params[:game]) 

    respond_to do |format| 
    if @game.save 
     format.html { redirect_to @game, notice: 'Game was successfully created.' } 
     format.json { render json: @game, status: :created, location: @game } 
    else 
     format.html { render action: "new" } 
     format.json { render json: @game.errors, status: :unprocessable_entity } 
    end 
    end 
end 

.

<% flash.each do |name, msg| %> 
    <div class="row-fluid"> 
    <div class="span12"> 
     <div class="alert alert-<%= name == :notice ? "success" : "error" %>"> 
     <a class="close" data-dismiss="alert">×</a> 
     <%= msg.html_safe %> 
     </div> 
    </div> 
    </div> 
<% end %> 

을 그래서 이미 그것을 처리 할 수 ​​있습니다,하지만 난 컨트롤러에 무슨 일을하는지 알 수 없을 : 내 application.html.erb 이미 있습니다. @game.errors이 무엇인지 또는 무엇이 채워지는지 알 수는 없지만 모델 유효성 검사에 실패하면 그 이유가 무엇인지 알 수 있습니다.

답변

관련 문제