# Calling another rjs file in an if condition

**URL:** <https://www.ruby-forum.com/t/calling-another-rjs-file-in-an-if-condition/137444>\
**Category:** Rails\
**Created:** [May 13, 2008, 7:21am UTC](https://www.ruby-forum.com/t/calling-another-rjs-file-in-an-if-condition/137444 "2008-05-13T07:21:43Z")\
**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:** [May 13, 2008, 7:21am UTC](https://www.ruby-forum.com/t/calling-another-rjs-file-in-an-if-condition/137444/1 "2008-05-13T07:21:43Z")

</div>

Hi  
I have a controller action like below.This def is called by a  
submit\_to\_remote  
def edit\_service\_desk\_status\_after\_transfer  
if params[:transfer\_reason].empty?  
#This is used in the :failure of submit\_to\_remote  
else  
@sd\_ticket = ServiceDeskTicket.find(params[:sd\_id])  
ActiveRecord::Base.transaction do  
@sd\_status\_history = ServiceDeskStatusHistory.new  
@sd\_status\_history.service\_desk\_ticket\_id = @sd\_ticket.id  
@sd\_status\_history.service\_desk\_status\_id =  
@sd\_ticket.service\_desk\_status\_id  
@sd\_status\_history.save  
@sd\_ticket.update\_attribute(“service\_desk\_status\_id”,params[:status\_id])  
end #end of transaction  
if params[:page]==‘search\_sd\_ticket’  
render :update do |page|  
#page[:flow\_item\_find\_search\_sd].replace\_html  
“service\_desk\_part/service\_desk\_flow\_item\_find\_search\_sd”,  
:locals=\>{:sd\_ticket=\>@sd\_ticket}  
end  
end  
#The below portion i dont want to execute if the above condition  
satisfied  
@sd\_activity\_history=@sd\_ticket.service\_desk\_status\_histories  
-------code  
end

In the above what i am trying to do is if the if condition  
if params[:page]==‘search\_sd\_ticket’ is satisfied call another rjs  
instead of the default rjs file  
edit\_service\_desk\_status\_after\_transfer.rjs .The above is not working  
.How can I do that…And I need not execute code after the if , if the  
condition is ok…Just load another rjs which has the code to replace  
some other divs rather than the default rjs does

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:** [May 13, 2008, 7:28am UTC](https://www.ruby-forum.com/t/calling-another-rjs-file-in-an-if-condition/137444/2 "2008-05-13T07:28:45Z")

</div>

On Tue, May 13, 2008 at 12:21 AM, Sijo Kg  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> In the above what i am trying to do is if the if condition  
> if params[:page]==‘search\_sd\_ticket’ is satisfied call another rjs  
> instead of the default rjs file

You can render an alternate RJS file with render.

render :controller =\> :foo, :action =\> :alternate\_bar

You can also just use an if/else in the RJS file.

–  
Greg D.  
[http://destiney.com/](http://destiney.com/)

---

<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:** [May 13, 2008, 11:35am UTC](https://www.ruby-forum.com/t/calling-another-rjs-file-in-an-if-condition/137444/3 "2008-05-13T11:35:56Z")

</div>

Hi  
Thanks for your reply.It worked  
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:** [May 14, 2008, 6:01am UTC](https://www.ruby-forum.com/t/calling-another-rjs-file-in-an-if-condition/137444/4 "2008-05-14T06:01:59Z")

</div>

Hi  
The above problem solved .But this too related to that problem .So I  
am posting in the same place.I have One more question related to this…I  
am calling the above function from different views but with differnt  
params…For example from one view page when i call this through  
submit\_to\_remote a particular param params[:page] is not passing .But  
from one other place I have to pass this param.Will this create any  
problem.Or this anything related to route.rb?Why i am asking this I had  
already this working…But as I said earlier last day i called this same  
function using submit\_to\_remote from another view with a param  
params[:page]=“search\_sd\_ticket” and checked it in an if else …So that  
is working…But the alredy working code now shows a failure from the  
other view?What might be the reason?Can’t i pass or not pass differnet  
params to the same function?

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:** [May 14, 2008, 3:11pm UTC](https://www.ruby-forum.com/t/calling-another-rjs-file-in-an-if-condition/137444/5 "2008-05-14T15:11:19Z")

</div>

It will be easier to help if you let us know what the failure is.

To answer your base question, the controller does not know or care  
where the request comes from. It will inspect the query string (via  
params), find the appropriate data to satisfy the request, and  
generate the response regardless of who asked for it or how (data  
problems excepted obviously).

One possibility would be that the rjs you generate may be trying to  
update a specific element on the page that only exists in one of the  
places that you call the action. You can code around that by using  
the page.select(…).any or by simply rendering the results and  
using :update on the ajax call. The choice lies in how many updates  
you make in your ajax response.
