Showing posts with label link_to_remote. Show all posts
Showing posts with label link_to_remote. Show all posts

Wednesday, February 2, 2011

How to make a remote call synchronous in Rails

new Ajax.Request('/controller/action?username=praveen', {asynchronous:false, evalScripts:true, parameters:'page_offset=' + page_offset + '&authenticity_token=' + encodeURIComponent('e060znd6JcrMCU6Bf4ZZnfyBac4tl1YXQ6HuEHZGY58=')});

What to do to get that "asynchronous:false" thing in your link_to_remote or any other helper function available in rails :)

I know its not a big thing and there is/are very few requirements to make an Ajax call synchronous but one might face this requirement sometimes, and the answers is
<%=remote_function(:url => {:controller => "controller", :action => "action", :username => "praveen"}, :type => :synchronous, :with => "'page_offset=' + page_offset") -%>

And you are done... so now till the time this thing is taking place, everything in browser will be waiting to complete the process first and then only proceed next.
Hope you stumble on me looking in for me.

Thursday, March 26, 2009

send_file or send_data in link_to_remote

Hi guys,

really really long time i did anything here :).. and no this time not an usual bhaana(excuse) will do but an genuine reason.. was busy building something good.. and it is a secret(just can't disclose it here like this).

Anyhow coming to point.. i was doing a general routine development task for my company and i got hit by a situation like this.. where i was making an ajax call to a controller/action and in response i was sending a stream i.e (send_data and send_file) but as the post was xmlhttp everything was working fine but download was not available (and yeh over here i coded it for download not the inline stuff). What to do now.... i searched it ya ya googled it and response was not a solution that i can rely on(it might not be google's fault must be mine, but why am i favoring it.. it must be google fault lol :)) )

So i solved it my own way by redirecting the update to other action and coding the stream in the newly redirected action :)

Here are some snippets of it....

<%=link_to_remote "Export the result",:url => {:controller => "some_controller", :action => "ask_to_export"},:with => "'record_ids=1-2-3-4-5-6'" -%>

def ask_to_export
render :update do |page|
page.redirect_to :action => "process_and_export", :record_ids => params[:record_ids]
end
end

def process_and_export
outfile = ""
CSV::Writer.generate(outfile) do |csv|
csv << ["praveen","kumar","sinha",1,2,3,nil,""]
end
send_data outfile, :type => 'text/csv; charset=iso-8859-1; header=present', :disposition => "attachment; filename=report_#{Time.now.to_f.to_s}.csv"
end

I hope this must be helpful to some one stucked over here and googling it

Thanks :)

Honda Civic & A/C problems.

Hello Friends, Got a post again on to Honda Civic (The good old favorite commuter of mine). This car has been doing great except for so...