Forum: Ruby on Rails Re: page.replace_html "#{var_containing_id_name}", :partial

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.
0430e2423183415d7688898faddb470f?d=identicon&s=25 Jason Tuttle (Guest)
on 2006-04-07 19:12
(Received via mailing list)
Jeff Coleman <progressions@...> writes:

 >
 > Jason Tuttle wrote:
 > > The subject line says it all. -- Is there a way to do something
like:
 > >
 > > page.replace_html "#{var_containing_id_name}", :partial => 'edit'
 > >
 > > That line of code does not work, but I would like to pass the
name of
 > > a variable to page.replace_html. This variable would contain the id
 > > of the div I want to update.
 > >
 > > Anyone know if/how I could do that?
 > >
 > > Thanks!
 > >
 > > : )
 > >
 > > Jason
 >
 > Convert the string with the ID name to a symbol?
 >
 > page.replace_html var_containing_id_name.to_sym, :partial => 'edit'
 >
 > perhaps?
 >
 > Jeff
 >

Thanks for the idea Jeff. -- Unfortunately, it doesn't seem to work.

: )

Jason
A2c85dc5ee81b12e3cc0a6522e8d079d?d=identicon&s=25 Chris Hall (Guest)
on 2006-04-07 19:27
(Received via mailing list)
you mean like this?

def do_some_ajax_thing
  @element_id = "content_div"
end

do_some_ajax_thing.rjs

page.replace_html @element_id, :partial => "edit"

remember, the view templates have access to the attributes defined in
the
controller
59ea1b450935b9d70abfec4186b7a4d5?d=identicon&s=25 Jeff Coleman (progressions)
on 2006-04-07 19:38
Jason Tuttle wrote:
> Jeff Coleman <progressions@...> writes:
>
>  >
>  > Jason Tuttle wrote:
>  > > The subject line says it all. -- Is there a way to do something
> like:
>  > >
>  > > page.replace_html "#{var_containing_id_name}", :partial => 'edit'
>  > >
>  > > That line of code does not work, but I would like to pass the
> name of
>  > > a variable to page.replace_html. This variable would contain the id
>  > > of the div I want to update.
>  > >
>  > > Anyone know if/how I could do that?
>  > >
>  > > Thanks!
>  > >
>  > > : )
>  > >
>  > > Jason
>  >
>  > Convert the string with the ID name to a symbol?
>  >
>  > page.replace_html var_containing_id_name.to_sym, :partial => 'edit'
>  >
>  > perhaps?
>  >
>  > Jeff
>  >
>
> Thanks for the idea Jeff. -- Unfortunately, it doesn't seem to work.
>
> : )
>
> Jason

I just did some experimenting, and I got this work to just fine
(adapting from Cody Fauser's template example:

add.rjs:

page.insert_html :bottom, 'list',
                 content_tag("li", "Fox")
page.visual_effect :highlight, 'list', :duration => 3
var_containing_id_name = 'animals'
page.replace_html var_containing_id_name,
                  'RJS Template Test Complete!'

Where is your var_containing_id_name defined?  If it's defined in your
controller, then try using an instance variable,
@var_containing_id_name.  Your view templates won't have access to any
local variables defined in your controller.

Jeff
This topic is locked and can not be replied to.