我仍在学习 RoR,并在线学习了各种教程。在那个过程中,我相信我搞砸了 Bootstrap 2 在验证 Simple_Form 提交时显示的漂亮的 Flash 通知。我试图更新我的代码,但没有成功。这是我到目前为止...
运行:Rails 3.2.13 Ruby 2.0.0
我刚刚在我的gemfile中使用这个 gem 升级到 Bootstrap 3 :
gem 'bootstrap-sass-rails'
在我的application.html.erb我有:
<%= render 'layouts/messages' %>
在我的_messages部分中,我有:
<% flash.each do |type, message| %>
<div class="alert <%= bootstrap_class_for(type) %> fade in">
<button class="close" data-dismiss="alert">×</button>
<%= message %>
</div>
<% end %>
在我的application_helper.rb我有:
def bootstrap_class_for flash_type
case flash_type
when :success
"alert-success"
when :error
"alert-error"
when :alert
"alert-block"
when :notice
"alert-info"
else
flash_type.to_s
end
end
在我的users_controller.rb我有:
def update
respond_to do |format|
if @user.update_attributes(params[:user])
format.html { redirect_to @user, notice: 'Account successfully updated.' }
format.json { head :no_content }
else
format.html { render action: "edit" }
format.json { render json: @user.errors, status: :unprocessable_entity }
end
end
end
在我的edit.html.erb视图中,我有:
<%= simple_form_for(@user) do |f| %>
<%= f.input :firstname %>
<%= f.input :lastname %>
<%= f.input :email %>
<%= f.input :password %>
<%= f.input :password_confirmation %>
<%= f.submit "Save changes", class: "btn btn-lg btn-primary" %>
<% end %>
验证有效,但是当返回到编辑视图时,没有格式(红色表示错误)或闪烁消息出现。仅显示每个字段之外非常难以发现的消息。我一定错过了 Simple_Form 和 Bootstrap 3 之间的一些链接,只是不知道是什么。
我发现另一个帖子,海报建议添加:
config.input_class = "form-control"
到我的 simple_form 初始化程序,但这给了我一个错误(认为我可能没有最新版本?):
undefined method `input_class=' for SimpleForm:Module (NoMethodError)
我希望我知道发生了什么,但我真的希望有人可以帮助我恢复格式和闪存消息。抱歉,如果这是一个完全新手的问题,但我感到有点失落,并且可能后悔我过早升级到 Bootstrap 3。
提前一千感谢所有阅读所有内容的人:)