title: Is there any issue with using respond_to blocks in controller actions like this?
body: <p>I'm AJAXifying an existing Rails 3.2 application, and some of the requests that are made from the client are better done asynchronously. To facilitate this, and to cut down on rendering time, I'm giving feedback to the user via alerts. I have a blank div in my application.html.erb file that I add alerts to as needed from certain controller actions like so:</p>
  
  <pre><code>def my_async_controller_action
    @user = User.find(params[:id])
    begin
      #@user.import
      flash[:notice] = "Your data is being downloaded."
    rescue Exception =&gt; bang
      flash[:alert] = "There was an error downloading your data: #{bang.message}"
    end
  
    respond_to do |format|
      format.js { render 'common/flashes' }
    end
  end
  </code></pre>
  
  <p>And my <code>common/flashes</code> file just uses jQuery to <code>append</code> the alerts to the blank div. While it works fine, I have never seen alerts delivered like this, only via redirects. Is there any unwritten (or written) Rails convention or rule that I'm breaking by taking this approach? Also, is there a way to instead do this as a respond_with? I can't see how I do two different types of rendering from a single line.</p>