How to remember if a div is shown or hidden after a page ref

Hi everyone, hi have a similar problem in a view:

...

Hide/show content

I would like the page to “remember” that the div has been hidden after a
page reload.
(The div comes up always visible even if it was set to hidden before).

Any simple way to do this?
Thanks a lot in advance

Ax Plains wrote:

Hi everyone, hi have a similar problem in a view:

...

Hide/show content

I would like the page to “remember” that the div has been hidden after a
page reload.
(The div comes up always visible even if it was set to hidden before).

Any simple way to do this?
Thanks a lot in advance

If you are reloading the page in the controller, then you can use an
instance variable in the controller to decide whether the div should be
hidden or not.Like,

In controller :
@show_div_tag = true

In view :
<% default_style = @show_div_tag ? “” : “display:none” %>

...

You can also optimize this code.

In case if you are manually reloading the browser, the above is
applicable.

Regards,

  • Karthi

Karthi kn wrote:

Ax Plains wrote:

Hi everyone, hi have a similar problem in a view:

...

Hide/show content

I would like the page to “remember” that the div has been hidden after a
page reload.
(The div comes up always visible even if it was set to hidden before).

Any simple way to do this?
Thanks a lot in advance

If you are reloading the page in the controller, then you can use an
instance variable in the controller to decide whether the div should be
hidden or not.Like,

In controller :
@show_div_tag = true

In view :
<% default_style = @show_div_tag ? “” : “display:none” %>

...

You can also optimize this code.

In case if you are manually reloading the browser, the above is
applicable.

Regards,

  • Karthi

Thanks a lot.

Anyway, I would like to let the user decide to let the div visible or
not.
I think the “show_div_tag” variable should be set when the user clicks
on the link, and remembered between page refreshes (maybe in a session)?

Karthi kn wrote:

Ax Plains wrote:

Thanks a lot.

Anyway, I would like to let the user decide to let the div visible or
not.
I think the “show_div_tag” variable should be set when the user clicks
on the link, and remembered between page refreshes (maybe in a session)?

Yes. You can use the session also. if you are not using the session, you
have to pass the current value of the variable to the controller for
each call(by manually passing the value or by submitting in the form as
a hidden value).

Many thanks.
In the end, I ended up using a cookie…
works fine and does not confuse Ruby coding.

Thanks a lot anyway.

Ax Plains wrote:

Thanks a lot.

Anyway, I would like to let the user decide to let the div visible or
not.
I think the “show_div_tag” variable should be set when the user clicks
on the link, and remembered between page refreshes (maybe in a session)?

Yes. You can use the session also. if you are not using the session, you
have to pass the current value of the variable to the controller for
each call(by manually passing the value or by submitting in the form as
a hidden value).

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs