Welcome to Working With Rails


Discussion Forums

Discuss all things Ruby on Rails with perhaps the web's most vibrant group of Ruby on Rails enthusiasts.
6 Posts
remote form tag

hello im anas .. im capable of using link_to_remote but i don't know how to use form_remote_tag.. plzz any one help me in details of using this one with examples

       thanking u 
                                                         mohd anas

form_remote_tag returns you a form tag that will submit your form using XMLHttpRequest in the background instead of the regular/normal POST

a small example

in your view

{ :controller => 'order', :action => :add_to_basket, :id =>"new_line_item"},

              :loading => "Element.show('XXXXX')",
              :complete => "Element.hide('XXXXX')" -%>

[-- your form content --]

you can access your post variables as usual in your controller

Forum Rating: 100
Sign In To Rate Post


form_remote_tag is used almost identically to form_tag, it will just post using AJAX, and will not refresh the screen. You do have some additional parameters for javascript that would not have with form_tag.

Kevin Elliott "WeLikeFood Beta":http://www.welikefood.com Great restaurants. Great reviews.

Balaji provides a nice example. One small thing though. I think 'end_form_tag' has been deprecated in favor of a block. So:

 { :controller => ‘order’, :action => :add_to_basket, :id =>”new_line_item”}, :loading => “Element.show(‘XXXXX’)”, :complete => “Element.hide(‘XXXXX’)” do -%>

and on that note, there is no reason why you might not also consider using form_remote_for instead of form_remote_tag, if you want to submit this form to update a model then really form_remote_for might be preferable. You might see something like:

add_to_basket_order_path(@order) do |form| %> etc etc etc

i point that out not to say to use one or another, but this lets you deal specifically with a model, so something to keep in mind.

Hi .. Make sure that you have included the jacascript tag prototype

The code for view goes here { :action => 'report_inapropriate'} ,:html => { :id =>"my_form1" }do |f| %> 35,:rows=>5%>

the code for controller goes here

if request.post?

    @reported_video= ReportedVideo.new(params[:reported_video])
     if @reported_video.save 
  # this is how you can control the page elements, by giving then different effects
 # for more effects pls refer to the   rjs cheat sheet!!
   render :update do |page|#rjs for posting comment and replacing the element
      flash[:notice] = "The video is been reported"
     page.replace_html :message, flash[:notice]
      page.visual_effect(:fade, 'report',  :duration => 0.5)
      page.visual_effect :highlight, 'message',  :duration => 2
     end #end for rjs   


more ever you can use the submit_to_remote tag this is how its shown... the view code goes here

{ :action => 'calculate_shipping' ,:controller=>'shop'},:loading
=> "Element.show('calculating');",:complete => "Element.hide('calculating');" ,:class=>"calculate_shipping"%>

The code for the controller will be as shown...

Best of Luck Thanks and regards Saurabh Purnaye http://saurabh.purnaye.googlepages.com

6 Posts
Login to add your message