# Calling another def

**URL:** <https://www.ruby-forum.com/t/calling-another-def/141973>\
**Category:** Rails\
**Created:** [July 2, 2008, 7:44am UTC](https://www.ruby-forum.com/t/calling-another-def/141973 "2008-07-02T07:44:42Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![sijo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/da6949/32.png) [@sijo](https://www.ruby-forum.com/u/sijo)\
**Post date:** [July 2, 2008, 7:44am UTC](https://www.ruby-forum.com/t/calling-another-def/141973/1 "2008-07-02T07:44:42Z")

</div>

Hi  
I already have a function  
def create  
#code here  
end

```
   It after execution call its view with same name..Now i have

```

another function create\_and\_give\_resolution  
This function is called from submit\_to\_remote In this function what I  
need is to call the aboe create def and some other extra code…But when  
I try like below nothing happens

def create\_and\_give\_resolution  
create  
#code continues  
render :update do |page|  
page.redirect\_to(:action =\> ‘edit\_sd\_ticket\_ui’, :id =\> 43)  
end  
end

Is this because create tries to render its view?If I am not calling  
create I get the desired result…Am I not trying in the right way?Please  
help me to solve this

Thanks in advance  
Sijo

---

<div class="post-metadata">

**Author:** ![sijo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/da6949/32.png) [@sijo](https://www.ruby-forum.com/u/sijo)\
**Post date:** [July 2, 2008, 8:22am UTC](https://www.ruby-forum.com/t/calling-another-def/141973/2 "2008-07-02T08:22:44Z")

</div>

On 2 Jul 2008, at 06:44, Sijo Kg wrote:

> what I  
> need is to call the aboe create def and some other extra code…But  
> when  
> I try like below nothing happens

It’s probably to do with the bit of create you’ve removed.

Fred

---

<div class="post-metadata">

**Author:** ![sijo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/da6949/32.png) [@sijo](https://www.ruby-forum.com/u/sijo)\
**Post date:** [July 2, 2008, 8:31am UTC](https://www.ruby-forum.com/t/calling-another-def/141973/3 "2008-07-02T08:31:32Z")

</div>

Why can’t you just put the create\_and\_give\_resolution code inside the  
create?

---

<div class="post-metadata">

**Author:** ![sijo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/da6949/32.png) [@sijo](https://www.ruby-forum.com/u/sijo)\
**Post date:** [July 2, 2008, 8:54am UTC](https://www.ruby-forum.com/t/calling-another-def/141973/4 "2008-07-02T08:54:22Z")

</div>

I think i cudn’t make you understand…I shall explain a bit more…Create  
function is the function i already have And I am calling that function  
from a view with link\_to So now in addition to create I have to give a  
resolution also.That I am calling by clicking another link which is a  
submit\_to\_remote.So I created a seperate function  
create\_and\_give\_resolution…In that I just call create (to avoid  
repitition) And after that add resolution and all(which is not needed in  
the original create function) And then redirect\_to another page…But  
this did not work.Because the create function has a view with same and  
at the bottom create def I am redirectiong as  
redirect\_to(:action =\> ‘edit\_sd\_ticket\_ui’, :id =\>  
@service\_desk\_ticket.id)

```
 So here I am in a situation to reuse the full code inside create 

```

but not redirect to the action Rather came back to  
create\_and\_give\_resolution and executing remaing portion …How can I do  
this…I think now you got it

Sijo

---

<div class="post-metadata">

**Author:** ![sijo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/da6949/32.png) [@sijo](https://www.ruby-forum.com/u/sijo)\
**Post date:** [July 2, 2008, 9:31am UTC](https://www.ruby-forum.com/t/calling-another-def/141973/5 "2008-07-02T09:31:17Z")

</div>

On 2 Jul 2008, at 07:54, Sijo Kg wrote:

> needed in  
> this…I think now you got it  
> factor out the common code into a function you call from both create  
> and create\_and\_give resolution.

Fred
