# Can't get .rjs files to be used automatically?

**URL:** <https://www.ruby-forum.com/t/cant-get-rjs-files-to-be-used-automatically/79075>\
**Category:** Rails\
**Created:** [December 12, 2006, 12:54am UTC](https://www.ruby-forum.com/t/cant-get-rjs-files-to-be-used-automatically/79075 "2006-12-12T00:54:43Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![nate](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/e95f7d/32.png) [@nate](https://www.ruby-forum.com/u/nate)\
**Post date:** [December 12, 2006, 12:54am UTC](https://www.ruby-forum.com/t/cant-get-rjs-files-to-be-used-automatically/79075/1 "2006-12-12T00:54:43Z")

</div>

I’m on EdgeRails, and I can’t seem to get .rjs files to be used  
automatically. I’ve looked at Cody’s (and others) tutorials, and I  
always have to say “.rjs”, even when it’s the only one there!

For example:

def show  
format.html { render :action =\> ‘show.rjs’ } # notice explicit  
“.rjs”  
end

Instead of:

def show  
format.html { render :action =\> ‘show’ }  
end

Anyone get this working?

---

<div class="post-metadata">

**Author:** ![nate](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/e95f7d/32.png) [@nate](https://www.ruby-forum.com/u/nate)\
**Post date:** [December 12, 2006, 1:24am UTC](https://www.ruby-forum.com/t/cant-get-rjs-files-to-be-used-automatically/79075/2 "2006-12-12T01:24:49Z")

</div>

Nate wrote:

> I can’t seem to get .rjs files to be used  
> automatically.  
>   
> Anyone get this working?

Absolutely. Have you deleted the other files? There’s a hirrarchy.

Bill

---

<div class="post-metadata">

**Author:** ![nate](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/e95f7d/32.png) [@nate](https://www.ruby-forum.com/u/nate)\
**Post date:** [December 12, 2006, 2:02am UTC](https://www.ruby-forum.com/t/cant-get-rjs-files-to-be-used-automatically/79075/3 "2006-12-12T02:02:56Z")

</div>

Yes, I’ve deleted the other files:

$ ls -1  
edit.rhtml  
index.rhtml  
new.rhtml  
show.rjs

show.rjs is the only one available for the show action

---

<div class="post-metadata">

**Author:** ![nate](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/e95f7d/32.png) [@nate](https://www.ruby-forum.com/u/nate)\
**Post date:** [December 12, 2006, 2:30am UTC](https://www.ruby-forum.com/t/cant-get-rjs-files-to-be-used-automatically/79075/4 "2006-12-12T02:30:58Z")

</div>

Got it: You have to put this in a format.js under EdgeRails:

def show  
@user\_role = UserRole.find(params[:id])  
respond\_to do |format|  
format.js { render :action =\> ‘show’ }  
format.html { raise “AJAX only for this action” }  
format.xml { render :xml =\> @user\_role.to\_xml }  
end  
end

---

<div class="post-metadata">

**Author:** ![nate](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/e95f7d/32.png) [@nate](https://www.ruby-forum.com/u/nate)\
**Post date:** [December 12, 2006, 2:49am UTC](https://www.ruby-forum.com/t/cant-get-rjs-files-to-be-used-automatically/79075/5 "2006-12-12T02:49:00Z")

</div>

Nah, nevermind - that fixed the updating problem, but I still have to  
say “.rjs”

```
respond_to do |format|
  format.js { render :action => 'show.rjs' }
  format.html { raise "AJAX only for this action" }
  format.xml { head :ok }
end

```

Any ideas??

---

<div class="post-metadata">

**Author:** ![nate](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/e95f7d/32.png) [@nate](https://www.ruby-forum.com/u/nate)\
**Post date:** [December 14, 2006, 12:18am UTC](https://www.ruby-forum.com/t/cant-get-rjs-files-to-be-used-automatically/79075/6 "2006-12-14T00:18:55Z")

</div>

Nate wrote:

> Nah, nevermind - that fixed the updating problem, but I still have to  
> say “.rjs”
> 
> ```
> respond_to do |format|
> format.js { render :action => 'show.rjs' }
> format.html { raise "AJAX only for this action" }
> format.xml { head :ok }
> end
> 
> ```
> 
> Any ideas??

try this:  
def show  
respond\_to do |format|  
format.js  
format.html { raise “AJAX only for this action” }  
format.xml { head :ok }  
end  
end

Also, make sure you are using link\_to\_remote, form\_remote\_tag or some  
other Ajax serialization method in the view that launches this method,  
otherwise the form is going to set the content type to html instead of  
JS.

Can you paste the view thatis calling this method and the show.rjs that  
you are using?

–jake

---

<div class="post-metadata">

**Author:** ![nate](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/e95f7d/32.png) [@nate](https://www.ruby-forum.com/u/nate)\
**Post date:** [December 14, 2006, 7:58pm UTC](https://www.ruby-forum.com/t/cant-get-rjs-files-to-be-used-automatically/79075/7 "2006-12-14T19:58:41Z")

</div>

Thanks Jake, I had resolved this already.

For some reason, I just needed to restart WEBrick. Must’ve had  
something cached internally.

It is working just like the example you show above. Thanks.
