RJS page question

Hey there I’m trying to test this condition in an RJS template

if page[‘search’].value == “somequerystring”

And it never returns true. Any ideas?

I’ve used page[‘element’] = value for setting a textbox in the past with
no problem. Not sure what checking the value would fail.

Thanks.

Guest wrote:


Posted via http://www.ruby-forum.com/.

RJS templates are a bit misleading. They are produced server side and
don’t have access to the state of the client side. So you can’t test
on the value of something on the page in the RJS template itself.

You can render a JS conditional, or you can pass the value you are
interested in as a parameter to the call that invokes the RJS action.

_Kevin

_Kevin,

That makes good sense. If anyone else runs into this, here’s the syntax

page << “if($(‘search’).value == ‘#{session[:value]}’) {”

do stuff here

page << “}”

Thanks _Kevin.

_Kevin wrote:

Guest wrote:


Posted via http://www.ruby-forum.com/.

RJS templates are a bit misleading. They are produced server side and
don’t have access to the state of the client side. So you can’t test
on the value of something on the page in the RJS template itself.

You can render a JS conditional, or you can pass the value you are
interested in as a parameter to the call that invokes the RJS action.

_Kevin

You might be interested in
http://www.agilewebdevelopment.com/plugins/rjs_if_unless_blocks
I don’t know if it does exactly what you’re interested in, but it’s
pretty good in other cases for getting rid of that fairly ugly syntax

Fred

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