# Coniditional loading of rjs files?

**URL:** <https://www.ruby-forum.com/t/coniditional-loading-of-rjs-files/117348>\
**Category:** Rails\
**Created:** [October 16, 2007, 5:54am UTC](https://www.ruby-forum.com/t/coniditional-loading-of-rjs-files/117348 "2007-10-16T05:54:13Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jessehk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/6bbea6/32.png) [@jessehk](https://www.ruby-forum.com/u/jessehk)\
**Post date:** [October 16, 2007, 5:54am UTC](https://www.ruby-forum.com/t/coniditional-loading-of-rjs-files/117348/1 "2007-10-16T05:54:13Z")

</div>

ok I have been struggling with this - seems very straight forward?

given a controller game\_controller with a method/action receive\_move  
that gets called by an ajax event on the client/browser I can  
‘automatically’ load an rjs file receive\_move.rjs, but if I try to do  
this in code it always appends .rhtml to the file name?

# the code that works but always loads the same rjs file

# when called from receive\_move action this loads up receive\_move.rjs

respond\_to do |format|  
format.js  
end

# this does not work

# looking at the log it is appending .rhtml to the file name

if standard\_move then  
respond\_to do |format|  
format.js { render :action =\> ‘receive\_move.rjs’ }  
end  
else  
respond\_to do |format|  
format.js { render :action =\> ‘receive\_move\_non\_standard.rjs’ }  
end  
end

found the above code on the net, maybe the approach is just plain wrong?  
Note that I can just code all of my rjs commands directly in the  
controller without issue?

running rails ‘1.2.3’

any help would be appreciated, Thanks!

---

<div class="post-metadata">

**Author:** ![jessehk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/6bbea6/32.png) [@jessehk](https://www.ruby-forum.com/u/jessehk)\
**Post date:** [October 16, 2007, 4:28pm UTC](https://www.ruby-forum.com/t/coniditional-loading-of-rjs-files/117348/2 "2007-10-16T16:28:48Z")

</div>

On 10/15/07, Jesse H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> but if I try to do  
> this in code it always appends .rhtml to the file name?

> end  
> Have you tried leaving the ‘.rjs’ off of your :action options?

–  
Rick DeNatale

My blog on Ruby  
[http://talklikeaduck.denhaven2.com/](http://talklikeaduck.denhaven2.com/)

---

<div class="post-metadata">

**Author:** ![jessehk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/6bbea6/32.png) [@jessehk](https://www.ruby-forum.com/u/jessehk)\
**Post date:** [October 16, 2007, 9:27pm UTC](https://www.ruby-forum.com/t/coniditional-loading-of-rjs-files/117348/3 "2007-10-16T21:27:51Z")

</div>

Try to create two new actions in controller: receive\_move and  
receive\_move\_non\_standard, and render them  
like render :action =\> :receive\_move\_non\_standard

---

<div class="post-metadata">

**Author:** ![jessehk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/6bbea6/32.png) [@jessehk](https://www.ruby-forum.com/u/jessehk)\
**Post date:** [October 16, 2007, 4:34pm UTC](https://www.ruby-forum.com/t/coniditional-loading-of-rjs-files/117348/4 "2007-10-16T16:34:23Z")

</div>

Rick Denatale wrote:

> Have you tried leaving the ‘.rjs’ off of your :action options?  
> My blog on Ruby  
> [http://talklikeaduck.denhaven2.com/](http://talklikeaduck.denhaven2.com/)

yes, I tried both ways  
render :action =\> ‘receive\_move\_non\_standard.rjs’ tries to load  
receive\_move\_non\_standard.rjs.rhtml

and  
render :action =\> ‘receive\_move\_non\_standard’ tries to load  
receive\_move\_non\_standard.rhtml

and both ways generate a ActionController::MissingTemplate in the log  
with the file name it is trying to load

---

<div class="post-metadata">

**Author:** ![jessehk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/6bbea6/32.png) [@jessehk](https://www.ruby-forum.com/u/jessehk)\
**Post date:** [October 17, 2007, 5:19am UTC](https://www.ruby-forum.com/t/coniditional-loading-of-rjs-files/117348/5 "2007-10-17T05:19:36Z")

</div>

Igor K. wrote:

> Try to create two new actions in controller: receive\_move and  
> receive\_move\_non\_standard, and render them  
> like render :action =\> :receive\_move\_non\_standard

excellent! that worked like a charm!

Thanks Igor!
