Sharing RJS Templates

Hello All,

I’m enjoying the simplicity and power of RJS templates in Rails 1.1, but
am
perplexed about sharing them. I have several templates that I would
like to
access in various controllers, but if I moved them to
views/shared/whatever.rjs, my app can’t seem to find them. I changed
the
name to _whatever.rjs and referenced them as “shared/whatever”, but no
luck.

Am I missing something? Or is it not possible to share them? It seems
like
it should be simple, and it would conform with DRY.

Actually, now that I’ve typed that out, it sorta makes sense that they
can’t
be shared like that, since they aren’t partials. So, maybe the broader
question is “How do I go about reusing RJS Templates throughout my
application?”

Regards,

-Ron

Ron,

You renamed it to _whatever.rjs, but when you do:

render :action => ‘shared/whatever’

Rails will look for whatever.rjs and not _whatever.rjs.

On 4/28/06, Ron M. [email protected] wrote:

it should be simple, and it would conform with DRY.


Rails mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails


Cody F.
http://www.codyfauser.com

“Ron M.” [email protected] writes:

Ahhhhhhh, since it’s not a partial, no underscore. Well, no. I must
be doing something wrong still. Actual code:

<%= link_to_remote( image_tag(“capsule_public.gif”, :size => “72x16”),
:url => { :action => ‘shared/script_status_cycle’, :id => @member.id })

I think your approach is wrong, you need to revise the chapter on
ActionPack.
It should be something like
<%= link_to_remote( image_tag(“capsule_public.gif”, :size => “72x16”),
:url => { :controller => ‘my_controller’, :action =>
‘script_status_cycle’, :id => @member.id })

And then in my_controller define

def script_status_cycle
blah…blah…code
render ‘./shared/script_status_cycle’
end

should do.
I think the above render should work, in case it doesn’t try:
render :template => ‘./shared/script_status_cycle’

I need to go to the “script_status_cycle” method in my controller,
then move to a shared component rather than one in the normal place.

HTH.

Surendra S.
http://ssinghi.kreeti.com, http://www.kreeti.com
Read my blog at: http://cuttingtheredtape.blogspot.com/
,----
| “O thou my friend! The prosperity of Crime is like unto the lightning,
| whose traitorous brilliancies embellish the atmosphere but for an
| instant, in order to hurl into death’s very depths the luckless one
| they have dazzled.” – Marquis de Sade
`----

Ron, did you figure this out ? Don’t have time to dig into it… but it
seems that being able to share RJS templates is not an option.

On 28/04/06, Ron M. [email protected] wrote:

ActionController::UnknownAction (No action responded to
shared/script_status_cycle), which tells me that it’s not actually the
RJS that is the problem, it’s the action. So I think my approach must
be wrong.

Hi Ron,

the following works for me:

my_controller.rb (excerpt)

def do_what_you_have_to_do
return render “shared/do_what_you_have_to_do.rjs”
end

Cheers,
Marco

Ahhhhhhh, since it’s not a partial, no underscore. Well, no. I must
be doing something wrong still. Actual code:

<%= link_to_remote( image_tag("capsule_public.gif", :size => "72x16"),
	:url => { :action => 'shared/script_status_cycle', :id => @member.id 

})

Should go to “shared/_script_status.cycle.rjs,” I would think. Or
“shared/script_cycle_rjs.” Neither seem to work.

I get this error:

ActionController::UnknownAction (No action responded to
shared/script_status_cycle), which tells me that it’s not actually the
RJS that is the problem, it’s the action. So I think my approach must
be wrong.

I need to go to the “script_status_cycle” method in my controller,
then move to a shared component rather than one in the normal place.

I think I’m over-thinking this, or missing something obvious.

To clarify after all that, I have an rjs template I want to use in 3
controllers. How do I accomplish that without having to keep 3 copies
of the template?

Thanks,

-Ron

On 4/28/06, Cody F. [email protected] wrote:

Actually, now that I’ve typed that out, it sorta makes sense that they can’t
[email protected]
Rails mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails


Ron M.
[email protected]
413.329.4277

Hi Ron

Ahhhhhhh, since it’s not a partial, no underscore. Well, no. I must
be doing something wrong still. Actual code:

   <%= link_to_remote( image_tag("capsule_public.gif" , :size =>

“72x16”),
:url => { :action => ‘shared/script_status_cycle’, :id =>
@
member.id })

Should go to “shared/_script_status.cycle.rjs,” I would think. Or
“shared/script_cycle_rjs.” Neither seem to work.

In the first example you have an _ at the front again.

in the second, your not calling the correct file.
script_cycle.rjs instead of script_status_cycle.rjs

Pat L. wrote:

It looks like you guys are on to something.

Pat, that’s interesting news that deserves being published in its own
thread, with a relevant subject line.

regards

Justin

Good evening,

The June/2006 issue of ‘Dr. Dobb’s Journal’ has, as the cover article,
“Ruby On Rails Java’s Successor?”.
The article starts on page 20.

In addition, on page 38, the book “Agile Web D. with Rails” was
awarded a Jolt Award.

On page 39, MySQL 5.0 was also given a Jolt Award.

Finally, for Web D. Tools, Rails 1.0 was given a Jolt Award.

It looks like you guys are on to something.

Ciao,
Pat

Hi,
I’ll create the thread, if someone will tell me how to do it.
Good weekend

Hi,
I started a new thread for this…
Cheers