Topic: Calling action method - no template

I basically want to be able to call a method in my controller, using the following:

<%= link_to_remote('Save', :update => "page", :url => {action => 'saveText', :id => @id} ) %>

However, i just want the action carried out - and no template generated. so i just want to stay with the same template but call an action method that will submit a form put something in the database and then update the current tamplate. Is this possible?

Re: Calling action method - no template

Yes, in fact it's very easy.  If you remove the :update part of that link it won't change any part of the page.  An additional benefit to removing :update => "page" from your link is that you can use RJS in the controller.

Note: I changed the method name because 'saveText' isn't a very ruby way of naming a method.

class PagesController
  def update_text
    # do what you want here
    # and set 'successful' equal to whether it worked or not (so you can get some feedback)
    successful = true
    render :update do |page|
      if successful
        page.visual_effect :highlight, 'form_01' # this will highlight something with an 'id' of 'form_01'
        page.visual_effect :shake, 'form_01' # this'll shake it

Last edited by danger (2006-11-19 14:16:59)

Re: Calling action method - no template

OK, thanks for your comments, i wonder if you can help some more..
What i am ultimately trying to do is:

I have a remote form, which when submitted calls an action update_file in my controller. I am not updating anything on the page yet the update_file call means that it still looks for an update_file template. I want it to just call the method and return to the current template.

I am then having trouble trying to use javascript after that. My form tag is as follows:

<%= form_remote_tag( :url => { :action => :updateFile, :id => @input }, :complete => "Effect.Highlight('my form') ) %>

OK, the only way i can call update_file and remain on the same template is to use redirect_to the update_file method, however this line is never executed for some reason?? However, this allows me to remain on the same template, but the javascript part doesn't have an effect..

any ideas?

Re: Calling action method - no template

I think you may have it pretty much working.  If you don't include an :update call to your form_remote_tag than the Ajax that powers your request won't update any part of your page.  So you don't have to worry about which template gets rendered because it would just be ignored anyway.  However, to avoid any errors showing up in your log file about a missing template you can make your update_file method do the following:

def update_file
  # do something with params or whatever
  render :text => ''

This way it won't render anything at all.

Does that solve the issue?