As title, I wonder what's the difference between Rails flash.discard and flash.delete.
#SteveTurczyn is right.
However, flash.delete is only possible to do in versions of rails previous to 3.1.
As of 3.1, flash.delete doesn't work anymore, an alternative might be flash.clear (check out flash.delete(:notice) not working in Rails 3.1 RC?).
You might also want to check: https://apidock.com/rails/v3.0.0/ActionDispatch/Flash/FlashHash/discard
flash.delete is immediate. flash.discard will remove the flash at the end of the current action.
So using flash.discard you can still examine the flash contents in the current action.
Related
I have upgraded my app from rails 2.x to rails 3.2. I have used render_message method http://apidock.com/rails/ActionMailer/Base/render_message
but it is deprecated in rails 3.
Please suggest any alternate method for this. I already tried to use template_name but it was not worked. Please help
It is deprecated in Rails 3, but looking at the source reveals that the replacement for render_message is simply render. Source:
# File actionmailer/lib/action_mailer/deprecated_api.rb, line 123
def render_message(*args)
ActiveSupport::Deprecation.warn "render_message is deprecated, use render instead", caller[0,2]
render(*args)
end
How would this be updated for Rails 3.1?
http://railscasts.com/episodes/88-dynamic-select-menus
I just can't figure out how to call the js.erb file and have it run the code to generate the javascript dynamically.
Might be something: in Rails 3.1, you're most likely using jQuery instead of Prototype. The example code on the Railscasts site is using good old Prototype instead of the new hotness that is jQuery (default javascript library in Rails 3.1).
Once all your jquery pipes are connected, having rails respond to and render your js.erb is the same as always. In your controller:
def country_selected
// whatever you need to do
respond_to do |format|
format.js
end
end
Then in your view directory, you have a country_selected.js.erb that you can put in whatever javascript you want to update the second select menu. (Remember you have to escape your shiz for it to work correctly) e.g.
<%= escape_javascript(params[:country]) %>
By the way, I think .rjs was moved out of Rails proper and into it's own Gem. Something else to keep in mind regarding Rails 3.1 vs. javascript.
Rails 2.3.9.
I have this action in my ProcurementsController...
def view_downloads
#downloads = Procurement.find(params[:id]).downloads
end
I want to render this view: views/procurements/view_downloads.html.haml.
When I just leave it like that what gets rendered is the Procurements index page. (I thought is was supposed to render the template with the same name as the action by default.)
I looked in the docs for the render method and found this...
Method deprecated
This method is deprecated on the latest stable version of Rails. The last existing version (v2.3.8) is shown here.
Zero info about what to use instead, or where to get further information.
Does that mean it's deprecated in Rails 3 but I can still use it if I'm using 2.x?
Or is there now some totally new way to indicate what template you want to render now? If so which versions of Rails does it apply to?
I have an application with Rails 2.3.5. And Im trying to use AS latest version, I have used it previously but cant make it work here.
I have my ingredient_categories Controller, where i put
class Administration::IngredientCategoriesController < ApplicationController
layout "default"
active_scaffold :ingredient_categories
end
I have this set up on routes to be :active_scaffold=>true
I have a model also called ingredient_category, and in the views folder (inside administration/ingredient_categories, and /ingredient_categories) i have nothing as it is usual.
And Im getting over and over again:
Template is missing
Missing template ingredient_categories/list.html in view path themes/aqueouslight:app/views
I had an error before asking me for a list.erb, which I created and put
'ingredient_categories', :label => 'Categorias' %>
And now this error of the list.thml...
Cant make it work! dont know whhy really... whould be SO simple and its burning my head now..
Thanks!
Make sure you have the render_component plugin installed, as it was deprecated from rails 2.3.x and is used by active scaffold
This may not be the cause of your particular problem but you will have trouble with it if you combine AS+Rails2.3.x
I hope it helps
I am talking about rails resource_controller gem plugin here:
Basically when I am doing json format, I would like to completely suppress the flash notice if possible, trying to call flash "" will fail, while calling flash[:notice]="" doesn't look really nice either. Is there some better approach?
I don't use that particular gem, but I think this should work anyway.
In your ApplicationController:
def set_xhr_flash
flash.discard if request.xhr?
end
Then just make sure you call it as an after_filter
after_filter :set_xhr_flash