2014-03-13 3 views
3

부트 스트랩 플래시 메시지에 문제가 있습니다. 플래시 메시지에서 일부 텍스트의 색을 변경해야합니다.레일에서 부트 스트랩 플래시 메시지를 수정하는 방법 4

컨트롤러

redirect_to complaints_path, notice: "Complaint was successfully created & Your Complaint Reference Id is #{@complaint.complaint_id}" 

나는 @ 불만/complaint_id

<% flash.each do |name, msg| %> 
    <div class="alert alert-<%= name == :notice ? "success" : "danger" %>"> 
    <span class="close" data-dismiss="alert">&times;</span> 
    <%= content_tag :div, msg, :id => "flash_#{name}" if msg.is_a?(String) %> 
    </div> 
<% end %> 

그것은 녹색 색상의 성공 메시지가 표시됩니다의 변화 색상을 가지고있다.

module ApplicationHelper 

    def bootstrap_class_for flash_type 
    { success: "alert-success", error: "alert-danger", alert: "alert-warning", notice: "alert-info" }[flash_type] || flash_type.to_s 
    end 

    def flash_messages(opts = {}) 
    flash.each do |msg_type, message| 
     concat(content_tag(:div, message, class: "alert #{bootstrap_class_for(msg_type)} fade in") do 
       concat content_tag(:button, 'x', class: "close", data: { dismiss: 'alert' }) 
       concat message 
      end) 
    end 
    nil 
    end 
end 

이 그런 다음 application.html.erb 레이아웃을 사용하지만 난

답변

1

당신은 플래시 메시지를 처리 ​​할 수있는 도우미를 만들 수 있습니다 .. 이 제발 도와주세요 .. 혼자 붉은 색 complaint_id 변경할 수 있습니다 :

<body> 
    <div class="container"> 

     <%= flash_messages %> 

     <%= yield %> 
    </div><!-- /container --> 
</body> 

이 DRY 방식을 원하지 않는 경우 필요에 맞게 조정할 수 있습니다.

관련 문제