Candidate for RJS?

It is not a good pratice to use render :update like that. When the RJS
is more than a one-liner, say, it is more clean to extract that to its
own RJS template. Because RJS belongs to the V in MVC.

On the other hand the idea of the loop + calls to page...something is
correct. In your example the ID of the element is always the same
though. Knowing this, you could for example simplify the code like
eliminating the conditional to get a wrong but working version, and
after that add all the logic.

That code *is* using RJS, that's what provides you the page object. It
is inline RJS instead of RJS in its own file, but it is RJS.

Render can happen only once, but several calls to the page object in
the same render do not account for serveral renders.

Your code uses a single ID, if you modify only one element, that's what you get.

If the real code is different please paste it.

Tyler Knappe wrote:

Xavier Noria wrote:

If the real code is different please paste it.

Here is the code:

Does anyone know why this would only render a single element? Does
anyone have a better way of doing this?

Thanks,

I am presumably missing something here, as I do not know much about
RJS, but inside the loop you seem to be replacing the html for the
same div ("test_div") every time round the loop.

Colin

> Here is the code:

Does anyone know why this would only render a single element? Does
anyone have a better way of doing this?

in your loop you're only updating the element with id test_div

Fred

Colin Law wrote:

           page\["test\_div\_7"\]\.replace\_html "Test 7"

"Checked Out"
else
page["test_div"].replace_html
"Available"
end
end
end
end

Executing this code only updates a single element.

I am presumably missing something here, as I do not know much about
RJS, but inside the loop you seem to be replacing the html for the
same div ("test_div") every time round the loop.

Colin

Oh. :facepalm:

Does anyone know how to dynamically generate div tags?

I tried this:

<th><div id = "test_div_" + ij"" style = "display :inline;"> Available
</div></th>

Which didn't work, rather it gives me this in the source:

        <th><div id = "test_div_" + ij"" style = "display :inline;">
Available </div></th>

The idea being that I would be able to use my loop to generate the div
tags.

Assuming you are in erb then <div id="test_div_#{i}#{j}" > or similar
should work

Colin

> Does anyone know how to dynamically generate div tags?

> I tried this:

> <th><div id = "test_div_" + ij"" style = "display :inline;"> Available
> </div></th>

> Which didn't work, rather it gives me this in the source:

> <th><div id = "test_div_" + ij"" style = "display :inline;">
> Available </div></th>

Assuming you are in erb then <div id="test_div_#{i}#{j}" > or similar
should work

I think you meant <%= i%> rather than #{i}

Fred

@Fred - I suppose if pushed I might reluctantly agree that your
suggestion has some validity. I think the moral is Engage brain before
typing.

Colin

Frederick Cheung wrote: