# Two links with one action

**URL:** <https://www.ruby-forum.com/t/two-links-with-one-action/126786>\
**Category:** Rails\
**Created:** [January 22, 2008, 7:34am UTC](https://www.ruby-forum.com/t/two-links-with-one-action/126786 "2008-01-22T07:34:12Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![fries88](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/6bbea6/32.png) [@fries88](https://www.ruby-forum.com/u/fries88)\
**Post date:** [January 22, 2008, 7:34am UTC](https://www.ruby-forum.com/t/two-links-with-one-action/126786/1 "2008-01-22T07:34:12Z")

</div>

Hi,

How do I have two links that does the same action, save, and redirects  
to different pages when different links are clicked. I am now using \<%=  
link\_to\_function ‘Previous’, “$(‘form\_id’).submit()” -%\>

Example:  
When user click the ‘Previous’ link, he will be redirected to the  
previous page. If the user click the ‘Next’ link, he will be redirected  
to the next page.

Can someone please help me?

Thanks

---

<div class="post-metadata">

**Author:** ![fries88](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/6bbea6/32.png) [@fries88](https://www.ruby-forum.com/u/fries88)\
**Post date:** [January 22, 2008, 8:19am UTC](https://www.ruby-forum.com/t/two-links-with-one-action/126786/2 "2008-01-22T08:19:54Z")

</div>

Hi,  
In link\_to\_function tag you can pass the id also depends upon the id  
you can redirect the pages.

```
link_to_function("Previous", "$('form_id').submit()", :id => 

```

“previous”)  
link\_to\_function(“Next”, “$(‘form\_id’).submit()”, :id =\> “next”)

Regards

Abirami s

---

<div class="post-metadata">

**Author:** ![fries88](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/6bbea6/32.png) [@fries88](https://www.ruby-forum.com/u/fries88)\
**Post date:** [January 22, 2008, 8:45am UTC](https://www.ruby-forum.com/t/two-links-with-one-action/126786/3 "2008-01-22T08:45:14Z")

</div>

Abirami S. wrote:

> Hi,  
> In link\_to\_function tag you can pass the id also depends upon the id  
> you can redirect the pages.
> 
> ```
> link_to_function("Previous", "$('form_id').submit()", :id => 
> 
> ```
> 
> “previous”)  
> link\_to\_function(“Next”, “$(‘form\_id’).submit()”, :id =\> “next”)
> 
> Regards
> 
> Abirami s

Hi,  
I tried the link\_to\_function(“Previous”, “$(‘form\_id’).submit()”, :id =\>  
“previous”)  
link\_to\_function(“Next”, “$(‘form\_id’).submit()”, :id =\> “next”)

and in the controller,

if params[:id] == “previous”  
redirect\_to :action =\> ‘previous\_page’  
elsif params[:id] == “next”  
redirect\_to :action =\> ‘next\_page’  
end

It gives me MISSING TEMPLATE error.Can someone tell me where did I go  
wrong?

Thanks

---

<div class="post-metadata">

**Author:** ![fries88](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/6bbea6/32.png) [@fries88](https://www.ruby-forum.com/u/fries88)\
**Post date:** [January 22, 2008, 10:01am UTC](https://www.ruby-forum.com/t/two-links-with-one-action/126786/4 "2008-01-22T10:01:06Z")

</div>

Abirami S. wrote:

> Hi,  
> do you have the rhtml page for previous\_page and next\_page
> 
> regards
> 
> Abirami

Hi,

Yes I do have previous\_page.rhtml and next\_page.rhtml. The MISSING  
TEMPLATE error says that my save action’s template is missing not the  
page that I want to redirect to is missing. I tried to use put to print  
out the id and the result it prints out is nil. How do I let my  
controller get the id from the link\_to\_function ?

Thanks

---

<div class="post-metadata">

**Author:** ![fries88](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/6bbea6/32.png) [@fries88](https://www.ruby-forum.com/u/fries88)\
**Post date:** [January 22, 2008, 9:55am UTC](https://www.ruby-forum.com/t/two-links-with-one-action/126786/5 "2008-01-22T09:55:53Z")

</div>

Hi,  
do you have the rhtml page for previous\_page and next\_page

regards

Abirami

---

<div class="post-metadata">

**Author:** ![fries88](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/6bbea6/32.png) [@fries88](https://www.ruby-forum.com/u/fries88)\
**Post date:** [January 22, 2008, 10:38am UTC](https://www.ruby-forum.com/t/two-links-with-one-action/126786/6 "2008-01-22T10:38:04Z")

</div>

Hi,  
Syntax for the link\_to\_function is

```
 link_to_function(name, *args, &block)

 like

 link_to_function("Previous",{:formId=>'form_id'},:id=>'previous')

 you can try this.... May be the params[:formId] have the value.

```

Regards

Abirami S

---

<div class="post-metadata">

**Author:** ![fries88](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/6bbea6/32.png) [@fries88](https://www.ruby-forum.com/u/fries88)\
**Post date:** [January 22, 2008, 10:50am UTC](https://www.ruby-forum.com/t/two-links-with-one-action/126786/7 "2008-01-22T10:50:33Z")

</div>

Abirami S. wrote:

> Hi,  
> Syntax for the link\_to\_function is
> 
> ```
> link_to_function(name, *args, &block)
> 
> like
> 
> link_to_function("Previous",{:formId=>'form_id'},:id=>'previous')
> 
> you can try this.... May be the params[:formId] have the value.
> 
> ```
> 
> Regards
> 
> Abirami S

Hi,

I tried the above code and it gives me an error saying, formIdform\_id is  
not defined. And it doesn’t submit anymore. Where did I do wrong?

Thanks

---

<div class="post-metadata">

**Author:** ![fries88](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/6bbea6/32.png) [@fries88](https://www.ruby-forum.com/u/fries88)\
**Post date:** [January 22, 2008, 11:17am UTC](https://www.ruby-forum.com/t/two-links-with-one-action/126786/8 "2008-01-22T11:17:37Z")

</div>

Hi,  
can you explain clearly from start

Regards

Abirami S
