私はまだ RoR を学んでおり、オンラインのさまざまなチュートリアルに従っています。その過程で、Simple_Form 送信の検証時に Bootstrap 2 が示したナイスなフラッシュ通知を台無しにしてしまったと思います。コードを更新しようとしましたが、成功しませんでした。これが私がこれまでに持っているものです...
実行中: 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 にアップグレードするのが早すぎたことを後悔している可能性があります。
これをすべて読んでくれた人に、前もって千の感謝を:)