# Directly calling an action

**URL:** <https://www.ruby-forum.com/t/directly-calling-an-action/149344>\
**Category:** Rails\
**Created:** [September 23, 2008, 9:22pm UTC](https://www.ruby-forum.com/t/directly-calling-an-action/149344 "2008-09-23T21:22:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![erhard](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/f19dbf/32.png) [@erhard](https://www.ruby-forum.com/u/erhard)\
**Post date:** [September 23, 2008, 9:22pm UTC](https://www.ruby-forum.com/t/directly-calling-an-action/149344/1 "2008-09-23T21:22:54Z")

</div>

Hi,

I have got now ajax to work in my application.

But I have still a small problem :

I have a content - section

…

......

Than I want to call a action which update this section depending on the  
data-constellation in the database.  
There is no input-field on the page.

It works fine when I create  
\<%=link\_to\_remote(“dispatchConstraint”,:update =\> “cont”,:url =\>  
{:action =\> :dispatch, :order\_id =\> @order}) %\>

My problem is : I do not want a link on the page. There is no field to  
observe and there is no periodic update necessery.

The action is :

def dispatch  
if (@order.cont==true)  
render :partial =\> “list”  
else  
render :partial =\> “addForm”  
end  
end

Is there any function to do this ?

What I learned is that the trigger comes from the browser but all  
functions I have found need an interaction or is periodically called.

Thanks for any idea

Erhard

---

<div class="post-metadata">

**Author:** ![erhard](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/f19dbf/32.png) [@erhard](https://www.ruby-forum.com/u/erhard)\
**Post date:** [September 24, 2008, 12:40pm UTC](https://www.ruby-forum.com/t/directly-calling-an-action/149344/2 "2008-09-24T12:40:37Z")

</div>

Erhard Karger wrote:

> {:action =\> :dispatch, :order\_id =\> @order}) %\> render :partial =\> "addForm"
> 
> Erhard

Erhard, if you only want to fill the div when the page is initially  
rendered, just make dispatch a helper function, and call it inside  
the div.

If instead you want to fill the div based on some unstated  
browser event, place a call to the remote\_function helper inside  
a (template-processed) JavaScript function or a tag event property:

[http://api.rubyonrails.org/classes/ActionView/Helpers/PrototypeHelper.html#M001635](http://api.rubyonrails.org/classes/ActionView/Helpers/PrototypeHelper.html#M001635)

–  
Rails Wheels - Find Plugins, List & Sell Plugins -  
[http://railswheels.com](http://railswheels.com)

---

<div class="post-metadata">

**Author:** ![erhard](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/f19dbf/32.png) [@erhard](https://www.ruby-forum.com/u/erhard)\
**Post date:** [September 26, 2008, 9:45pm UTC](https://www.ruby-forum.com/t/directly-calling-an-action/149344/3 "2008-09-26T21:45:26Z")

</div>

Hi Thank You a lot.

I took the first aproach and filled the div with a partial initially  
with (remote\_form\_for)

in create I call a format.js with :

file : create.js.rjs  
page.replace\_html :constraintCont, " "  
page.insert\_html :bottom, :constraintCont,:partial =\> “list”, :object =\>  
@constraint

Now the next step (I’ll do this weekend) is to call the form partial  
again.  
(I hope it works with an ajax Button)

Erhard

Mark Reginald J. wrote:

> Erhard Karger wrote:
> 
> > {:action =\> :dispatch, :order\_id =\> @order}) %\> render :partial =\> "addForm"
> > 
> > Erhard
> 
> Erhard, if you only want to fill the div when the page is initially  
> rendered, just make dispatch a helper function, and call it inside  
> the div.
> 
> If instead you want to fill the div based on some unstated  
> browser event, place a call to the remote\_function helper inside  
> a (template-processed) JavaScript function or a tag event property:
> 
> [http://api.rubyonrails.org/classes/ActionView/Helpers/PrototypeHelper.html#M001635](http://api.rubyonrails.org/classes/ActionView/Helpers/PrototypeHelper.html#M001635)
> 
> –  
> Rails Wheels - Find Plugins, List & Sell Plugins -  
> [http://railswheels.com](http://railswheels.com)
