Forum: Ruby on Rails DOM values in ERB Variable?

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.
Eric W. (Guest)
on 2006-05-31 01:31
(Received via mailing list)
I am trying to post the current brower window sizes into the user's
session file with a form_remote_tag call as follows:

<%= form_remote_tag :url => url_for(:controller => "welcome", :action
=> "login", :iheight => "1", :iwidth => "2") %>

But how do I get the DOM data for window.innerHeight and
window.innerWidth into an ruby ERB variable such that I can put into
the helper, and POST them in to the controller? Or is there a better
way? I feel like I am missing some really simple here.

Anyone come up against this, and / or know the answer? If so, please
help.

--ejw

Eric W.
Email: removed_email_address@domain.invalid
Alex W. (Guest)
on 2006-05-31 03:47
Eric W. wrote:
> I am trying to post the current brower window sizes into the user's
> session file with a form_remote_tag call as follows:
>
> <%= form_remote_tag :url => url_for(:controller => "welcome", :action
> => "login", :iheight => "1", :iwidth => "2") %>
>
> But how do I get the DOM data for window.innerHeight and
> window.innerWidth into an ruby ERB variable such that I can put into
> the helper, and POST them in to the controller? Or is there a better
> way? I feel like I am missing some really simple here.
>
> Anyone come up against this, and / or know the answer? If so, please
> help.
>
> --ejw
>
> Eric W.
> Email: removed_email_address@domain.invalid

Since Rails doesn't actually run on the client, rails only has the info
that was included in the request to go on, and screen size is not in the
request that browser make to your app.

So...

You need to render the page first and then use javascript to trigger an
AJAX call that posts some variables back to the server.  Something like

Ajax.Request('/users/screen_size?width='+screenWidth()+'height='+screenHeight());
This topic is locked and can not be replied to.