# Embed JS/RJS from remote

**URL:** <https://www.ruby-forum.com/t/embed-js-rjs-from-remote/119056>\
**Category:** Rails\
**Created:** [November 2, 2007, 5:12pm UTC](https://www.ruby-forum.com/t/embed-js-rjs-from-remote/119056 "2007-11-02T17:12:06Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Matthew\_Swasey](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/f07891/32.png) [@Matthew\_Swasey](https://www.ruby-forum.com/u/Matthew_Swasey)\
**Post date:** [November 2, 2007, 5:12pm UTC](https://www.ruby-forum.com/t/embed-js-rjs-from-remote/119056/1 "2007-11-02T17:12:06Z")

</div>

I’m trying to make a widget for a page, that will go on other people’s  
pages if they choose to do so.

What I am wanting to do, is have a resource like

map.resource :widget

So that localhost/widget is mapped to :controller =\> widget, :action  
=\> show, as is default with singular resource.

That way if someone browses to localhost/widget, they can see some  
html/erb explaining how to use the widget, and then if they

in there webpage, they can have the widget rendered on their page.

I thought I might be able to do this, by setting a respond\_to in the  
show action like this:

def show  
…  
…

respond\_to do |format|  
format.html { do some normal html rendering }  
format.js { render the widget }  
end  
end

So then I created a file called show.rjs, and tried writing some very  
basic rjs, just to see if it would work, and it totally did not. So I  
tried a bunch of different approaches in the rjs file, especially the  
page \<\< ‘raw javascript’ kind of thing, I really thought that was  
going to work, but no deal.

Also, I tried renaming show.rjs to just show.js, same thing nothing.

Does anyone know what I am doing wrong here? Does anyone know what a  
better solution for me would be?

Thanks for listening.
