Forum: Ruby on Rails Sharing RJS Templates

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Ron M. (Guest)
on 2006-04-28 20:21
(Received via mailing list)
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
Cody F. (Guest)
on 2006-04-28 21:31
(Received via mailing list)
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. <removed_email_address@domain.invalid> wrote:
> it should be simple, and it would conform with DRY.
> _______________________________________________
> Rails mailing list
> removed_email_address@domain.invalid
> http://lists.rubyonrails.org/mailman/listinfo/rails
>
>
>


--
Cody F.
http://www.codyfauser.com
Ron M. (Guest)
on 2006-04-28 22:15
(Received via mailing list)
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. <removed_email_address@domain.invalid> wrote:
> >
> > Actually, now that I've typed that out, it sorta makes sense that they can't
> > removed_email_address@domain.invalid
> Rails mailing list
> removed_email_address@domain.invalid
> http://lists.rubyonrails.org/mailman/listinfo/rails
>


--
Ron M.
removed_email_address@domain.invalid
413.329.4277
Surendra S. (Guest)
on 2006-04-29 00:30
(Received via mailing list)
"Ron M." <removed_email_address@domain.invalid> 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
`----
Dylan S. (Guest)
on 2006-05-11 01:19
(Received via mailing list)
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.
Marco L. (Guest)
on 2006-05-11 03:16
(Received via mailing list)
On 28/04/06, Ron M. <removed_email_address@domain.invalid> 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
Pat L. (Guest)
on 2006-05-11 03:56
(Received via mailing list)
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
Daniel -. (Guest)
on 2006-05-11 03:59
(Received via mailing list)
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
Justin F. (Guest)
on 2006-05-11 21:25
(Received via mailing list)
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
Pat L. (Guest)
on 2006-05-12 04:28
(Received via mailing list)
Hi,
I'll create the thread, if someone will tell me how to do it.
Good weekend
Pat L. (Guest)
on 2006-05-12 05:44
(Received via mailing list)
Hi,
I started a new thread for this...
Cheers
This topic is locked and can not be replied to.