i.e.:
I click on a link_to_remote link, and the content of an action is put
into an <div>
Yes. You're interested in RJS. You can do it a few ways. One is to
provide the element to update in the call itself, which means you will
just do a render in the controller. Another is to use render :update in
the controller and specify which element gets updated. You can also use
rjs partials so the updating code is not cluttering up your controller.
i.e.:
I click on a link_to_remote link, and the content of an action is put
into an <div>
Yes. You're interested in RJS. You can do it a few ways. One is to
provide the element to update in the call itself, which means you will
just do a render in the controller. Another is to use render :update in
the controller and specify which element gets updated. You can also use
rjs partials so the updating code is not cluttering up your controller.
Peace,
Phillip
I tried RJS and :update, but it didn't really workt. could you provide
me a small example?
Run script/server, navigate to http://localhost:3000/time, and click the
Current Time link. You should see the current time appear right below
the link. Click it again and you should see the time refresh.
If the code gets munged, I'll post again with something that will not
be technically correct but will hopefully be useful.
Run script/server, navigate to http://localhost:3000/time, and click the
Current Time link. You should see the current time appear right below
the link. Click it again and you should see the time refresh.
If the code gets munged, I'll post again with something that will not
be technically correct but will hopefully be useful.
Peace,
Phillip
well, that's nothing new to me. My problem is rendering a view or HTML
template into a div. i.e.:
you have following in your opened page:
<div id="div1"></div>
and I want to add this snippet into it:
<h1>Hello @User.id</h1>
<p>Lorem ipsum dolor sit amet...</p>
The other way to do it (specifying the element to update in the call)
would be done like this:
app/controllers/time_controller.rb
def now
render :text => Time.now.to_s
end
Note that render :text can also be render :inline. They both seem to
have the same result, but I don't know if the implementation of one is
better than the other.
Hm. Okay. Sorry I insulted your intelligence. You asked for a small
example. I showed you one.
My problem is rendering a view or HTML
template into a div. i.e.:
you have following in your opened page:
<div id="div1"></div>
and I want to add this snippet into it:
<h1>Hello @User.id</h1>
<p>Lorem ipsum dolor sit amet...</p>
is that possible?
Yes. I posted another message that indicated you can use partials. As
far as I know, you cannot use a standard view. It must be a partial. I
might be wrong in that, though. The AJAX call will be the same (and you
can pass parameters if you need to), and in the controller action, do
whatever you need to, and render a partial.
I do this in a situation in which I'm editing a resource. Suppose I have
a widget that I want to edit, I might have a form that looks like