Link_to_function

I require some information, displayed at the top of a page, to change
onclick.

The information is in the following form:

Name
Job role

Description... <%= link_to "read more", :controller => "controller", :action => "show", :id => id %>

telephone number

There is an image to correspond with this. The image is not a problem; I
have gotten this image to change on click with ‘link_to_function’.

The information above, excluding the image of course, also needs to
change on click.

What is the best method of doing this?

Hi,

On Mon, Aug 23, 2010 at 8:38 AM, Pale H. [email protected]
wrote:

There is an image to correspond with this. The image is not a problem; I
have gotten this image to change on click with ‘link_to_function’.

The information above, excluding the image of course, also needs to
change on click.

If you know at the time of rendering the initial display what
information needs to be displayed when the link is clicked, then you
should probably render both sets of info inside two

s: one with
style=“display:block” and the other with style=“display:none”. Then
your link_to_function can simply toggle the display settings.

If you don’t, then I’d recommend using a link_to_remote instead and
hitting the server to remove the first

and render the second
using an RJS template.

HTH,
Bill

Bill W. wrote:

Hi,

On Mon, Aug 23, 2010 at 8:38 AM, Pale H. [email protected]
wrote:

There is an image to correspond with this. The image is not a problem; I
have gotten this image to change on click with ‘link_to_function’.

The information above, excluding the image of course, also needs to
change on click.

If you know at the time of rendering the initial display what
information needs to be displayed when the link is clicked, then you
should probably render both sets of info inside two

s: one with
style=“display:block” and the other with style=“display:none”. Then
your link_to_function can simply toggle the display settings.

I know what information needs to be displayed when the user clicks the
tab with the name on it. There are 4 tabs and therefore 4 pieces of
information that all use the same class. I’m trying to use a toggle
feature but it doesn’t seem to be working.

If you don’t, then I’d recommend using a link_to_remote instead and
hitting the server to remove the first

and render the second
using an RJS template.

HTH,
Bill

Hi,

On Mon, Aug 23, 2010 at 10:02 AM, Pale H. [email protected]
wrote:

If you know at the time of rendering the initial display what
information needs to be displayed when the link is clicked, then you
should probably render both sets of info inside two

s: one with
style=“display:block” and the other with style=“display:none”. Then
your link_to_function can simply toggle the display settings.

I know what information needs to be displayed when the user clicks the
tab with the name on it. There are 4 tabs and therefore 4 pieces of
information that all use the same class. I’m trying to use a toggle
feature but it doesn’t seem to be working.

‘not working’ isn’t much to go on in terms of providing additional
help. Post some code; both the html.erb and the js function and maybe
we can say more.

Best regards,
Bill

Bill W. wrote:

Hi,

On Mon, Aug 23, 2010 at 10:02 AM, Pale H. [email protected]
wrote:

If you know at the time of rendering the initial display what
information needs to be displayed when the link is clicked, then you
should probably render both sets of info inside two

s: one with
style=“display:block” and the other with style=“display:none”. �Then
your link_to_function can simply toggle the display settings.

I know what information needs to be displayed when the user clicks the
tab with the name on it. There are 4 tabs and therefore 4 pieces of
information that all use the same class. I’m trying to use a toggle
feature but it doesn’t seem to be working.

‘not working’ isn’t much to go on in terms of providing additional
help. Post some code; both the html.erb and the js function and maybe
we can say more.

Indeed it’s not. See below, the functions used:

The call to these functions is below:

<%= link_to_function "Name 1", "changeImage('/images/name_1_large.jpg'); toggleInformation(name_1);", {:style => "width: 64px;"} %> <%= link_to_function "Name 2", "changeImage('/images/name_2_large.jpg'); toggleInformation(name_2);", {:style => "width: 57px;"} %> <%= link_to_function "Name 3", "changeImage('/images/name_3_large.jpg'); toggleInformation(name_3);", {:style => "width: 56px;"} %> <%= link_to_function "Name 4", "changeImage('/images/name_4_large.jpg'); toggleInformation(name_4);", {:style => "width: 71px;"} %>

The divs are below:

Full Name 1
Job Role 1

Information here... <%= link_to "read more", :controller => "staffs", :action => "show", :id => 4 %>

Telephone Number

The divs above are repeated for each of the staff members (4 in total),
I set the style of the other 3 as “display:none”.

Best regards,
Bill

On Mon, Aug 23, 2010 at 9:38 AM, Pale H. [email protected]
wrote:

There is an image to correspond with this. The image is not a problem; I
have gotten this image to change on click with ‘link_to_function’.

The information above, excluding the image of course, also needs to
change on click.

What is the best method of doing this?

Hey there,

Is that information already loaded in the page you are currently on?
If so, couldn’t the function just swap out the content?

If not, and the more correct way of doing this, would be to hit some
sort of restful resource with link_to_remote and have it return
javascript to update the page with the retrieved information.

For example, slightly dated:

  • Chris