rails-flash

How to display a Rails flash notice upon redirect?

若如初见. 提交于 2021-01-20 14:36:48
问题 I have the following code in a Rails controller: flash.now[:notice] = 'Successfully checked in' redirect_to check_in_path Then in the /check_in view: <p id="notice"><%= notice %></p> However, the notice does not show up. Works perfect if I don't redirect in the controller: flash.now[:notice] = 'Successfully checked in' render action: 'check_in' I need a redirect though... not just a rendering of that action. Can I have a flash notice after redirecting? 回答1: Remove the .now . So just write:

Rails flash with warning, alert and error not shown; only notice shown

老子叫甜甜 提交于 2019-12-23 10:17:09
问题 In my view, I have: <% flash.now[:error] = "ERROR FLASH" %> <% flash.now[:notice] = "NOTICE FLASH" %> <% flash.now[:warning] = "WARNING FLASH" %> When the page gets render, only the blue info box with NOTICE FLASH appears. The other two will not be shown. The same thing happens with the equal signs: <%= flash.now[:error] = "ERROR FLASH" %> <%= flash.now[:notice] = "NOTICE FLASH" %> <%= flash.now[:warning] = "WARNING FLASH" %> Is there a setting in my rails app that sets warning or error

Accessing rails flash[:notice] in a model

我怕爱的太早我们不能终老 提交于 2019-11-30 06:38:08
问题 I am trying to assign a message to flash[:notice] in a model observer. This question has already been asked: Ruby on Rails: Observers and flash[:notice] messages? However, I get the following error message when I try to access it in my model: undefined local variable or method `flash' for #<ModelObserver:0x2c1742c> Here is my code: class ModelObserver < ActiveRecord::Observer observe A, B, C def after_save(model) puts "Model saved" flash[:notice] = "Model saved" end end I know the method is

Rails doesn't display flash messages after ajax call

杀马特。学长 韩版系。学妹 提交于 2019-11-28 18:26:29
I'm writing a rails 4.0.2 app, and am trying to get a Flash notice to display in my view after an AJAX event. In my view I display a calendar with days a user can click on. When they do so, I fire an AJAX event via an onclick event handler which updates my model, either adding or removing a record. After firing the event, I complete a page refresh in order to display the updated results. I found I had to do a page refresh during the JS click event in order to get the view to update properly. A redirect or render in the controller alone wasn't enough. So, to that effect, I have set a Flash

Rails doesn't display flash messages after ajax call

时光毁灭记忆、已成空白 提交于 2019-11-27 11:20:35
问题 I'm writing a rails 4.0.2 app, and am trying to get a Flash notice to display in my view after an AJAX event. In my view I display a calendar with days a user can click on. When they do so, I fire an AJAX event via an onclick event handler which updates my model, either adding or removing a record. After firing the event, I complete a page refresh in order to display the updated results. I found I had to do a page refresh during the JS click event in order to get the view to update properly.