Ruby and rjs

Hi all…

Can we write ruby code directly in an rjs file?

I have to replace a div with

<%= text_field “ciclass”, “name”, “size” => 20, “value” => @class_name,
:readonly => “readonly” %>
<%= hidden_field “ci”, “ci_class”, “value” => @class_id %>

For doing this i’ve to write the above code in a partial file and
update the div as follows in the rjs file as shown below:

page.replace_html “div_name”, :partial => “partial_file_name”

I was looking for a simpler way so that i can avoid writing a partial
file for the above 2 lines.

Is there any way to write the above code directly in rjs file?

Please help

Thanks
Regards
Suneeta

Suneeta Km wrote:

Can we write ruby code directly in an rjs file?

rjs files themselves might be overkill. I have never needed to do
anything but
this, straight out of a controller:

render :update do |rjs|
rjs.replace_html “div_name”, :partial => “partial_file_name”
end

(The variable that’s usually called ‘page’ I renamed to ‘rjs’, because
the
Interthing already has too danged many variables in it called ‘page’.)

And I would not hesitate to write a two-line partial. But you might get
by with
an inline:

rjs.replace_html “div_name”, :inline =>
“<%= text_field ‘ciclass’, ‘name’, :size => 20,
:value => #{@class_name},
:readonly => “readonly” %>
<%= hidden_field ‘ci’, ‘ci_class’, :value => #{@class_id} %>”

Is there any way to write the above code directly in rjs file?

Instead of stomping out an entire div (and possibly twitching the user’s
keyboard focus) can’t you just update those fields’ values directly?


Phlip

Phlip wrote:

Instead of stomping out an entire div (and possibly twitching the user’s
keyboard focus) can’t you just update those fields’ values directly?


Phlip

Hi…

I solved the problem by writing a 2 line partial file and rendering it
in rjs file.

I tried to update those field values alone directly. I have some other
fields in the form. So when i select their value, the above updated
value is not shown.

So i did it this way

Thanks
Suneeta

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