Rails 3 Javascript Not Executed Despite A Text/javascript Content-type In Response
I am performing an non-ajax GET request on a page. In the corresponding controller/action, I am returning javascript. However, this javascript is not being executed. Rather, it is
Solution 1:
If you want to achieve what you stated in the comments: "User wants to go to page Y from page X, but there's an error." The standard way to do this is set the flash[:error] hash to your message, and redirect back to the referring page. In your layout you'd have some erb snippet like:
<% if flash[:error %>
<div class='flash error'><%= flash[:error] %></div>
<% end %>
And on your controller you'd set up a before filter like:
before_filter :validate_user
def before_filter
if <some condition is not met>
flash[:error] = "Oops...you are not logged in"
redirect_to :back # or some_defined_path
end
end
Post a Comment for "Rails 3 Javascript Not Executed Despite A Text/javascript Content-type In Response"