【发布时间】:2016-06-18 08:42:40
【问题描述】:
我正在尝试在 rails 5 应用程序中添加 flash msg Bootstrap 3 haml。无论如何,只会显示 case 语句 else 部分中的 flash-info。我的代码有什么问题
module ApplicationHelper
def twitterized_type(type)
case type.to_s
when :errors
"alert-danger"
when :alert
"alert-danger"
when :error
"alert-danger"
when :notice
"alert-success"
when :success
"alert-success"
when :warning
"alert-warning"
else
"alert-info"
end
end
application.html.haml 中的闪存消息
.container
- flash.each do |type, message|
.alert.alert-dismissable{ :class => twitterized_type(type) }
= message
%button.close{ data: { dismiss: 'alert' } } x
控制器:
def create
@pin = current_user.pins.build(pin_params)
if @pin.save
# Display success flash message then redirect to the saved pin
flash[:success] = 'New pin saved successfully'
redirect_to @pin
else
# Display a fail flash message and render new
flash[:alert] = 'New pin failed to save, please try again'
render 'new'
end
def update
if @pin.update_attributes(pin_params)
# save update and display success flash message
flash[:success] = 'Pin was updated successfully'
redirect_to @pin
else
# flash error message and redirect to edit
flash[:alert] = 'Pin failed to update, please try again'
render 'edit'
end
如何使 flash 与预期的类一起显示
【问题讨论】:
标签: ruby-on-rails twitter-bootstrap flash