Is it possible to use redirect_to when it's called by remote ajax?
ajax, ruby-on-rails, ruby-on-rails-3
Solution
You will have to write this code in js instead of controller.
In controller:
def action_name
....
respond_to do |format|
format.js
end
end
Make a action_name.js.erb file and write this code:
<% if params[:comment][:call] == "1" %>
<% flash[:notice] = "you checked and submit!" %>
window.location.href = <%= some_url %>
<% else %>
$("#some_div_id").html("something") //ajax page reload
<% end %>
Hope this will work for you.
Problem
Now this action in this controller is called by remote ajax call. Only when the checkbox[:call] was checked and it's submit, I'd like make it to redirect to ......_path with flash message. Is it possible? if possible, how? controller ``` ..... if params[:comment][:call] == "1" flash[:notice] = "you checked and submit!" redirect_to ....._path else ajax page reload end ``` view Form (remote with ajax) ``` <%=form_for(([@community, @comment]), :remote => true, :class => 'form' ) do |f| %> <%= f.check_box :call, :label => 'call' %> call <div class="form-actions"> <div class="input-append"> <%= f.text_field :body, :id => "input", :class => "box" %> <button type="submit" class="btn">submit</button> </div> </div> <% end %> ``` Comment model ``` attr_accessible :icon, :call .... def call @call ||= "0" end def call=(value) @call = value end ```