Link_to_remote the right way in Rails 3.0?

I have been using link_to_remote forever now. I have also been using
jquery through jrails.

I am readying my code for Rails 3.0, and am wondering what is the best
way to accomplish.

For example, I have something like this all over in Rails 2.0

<%= link_to_remote “XXX”,
{ :url => “/activities/hide_dock”, :update =>
“dock-container”, :complete => “fixDock()” }, { :class => “activities” }
%>

def hide_dock
render :partial => “/layouts/dock”
end

Now, in Rails 3.0 I am planning this

<%= raw link_to “XXX”, “/activities/hide_dock”,
{:remote => true, :class => “activities” }
%>

def hide_dock
respond_to do |format|
format.html
format.js do
??? What do I put here ???
end
end
end

My main question is since I am using jQuery, is there any point in using
RJS?

Should I just have

render :layout => false

and in hide_dock.js.erb just use jQuery code with <%= render :partial
=>%> where appropriate.

On Thu, Jun 17, 2010 at 9:51 PM, Sharkie L.
[email protected]wrote:

“dock-container”, :complete => “fixDock()” }, { :class => “activities” }
%>

Sharkie, I would recommend reading the following first before you start
upgrading from Rails 2.x to Rails 3.x:

http://blog.peepcode.com/tutorials/2010/live-coding-rails-3-upgrade

Next, link_to_remote has been deprecated in Rails 3 and you would
need to do the following:

<%= link_to “XXX”, { :remote => true }, { … } %>

Next, the above shouldn’t use raw because link_to method
returns an html_safe string in Rails 3.

def hide_dock
respond_to do |format|
format.html
format.js do
??? What do I put here ???

If you’re using RJS, then you’ll simple add
the expression to be executed. For example,
I tend to be partial to JSON and I would do the
following:

format.js # render the action.js.rjs by default

or you can redefine it as follows to return json

format.js { render :json => @some_object }

 end

end
end

It’s not clear as to what you’re trying to do. The hide_dock is a
controller
action so do you want to allow the following:

http://some_domain.com/controller_name/hide_dock

My main question is since I am using jQuery, is there any point in using
RJS?

If you intend on using jQuery, then there’s no need to use RJS. Just
make
sure that you get the JS file here:

Should I just have

render :layout => false

If you’re updating just a part of the page, then you’ll need to use the
above.

and in hide_dock.js.erb just use jQuery code with <%= render :partial
=>%> where appropriate.

Lastly, I would recommend getting the PDF for “Agile Web D.
with
Rails 4th Ed” by Sam Ruby, Dave T., et al from pragprog.com for
additional
information regarding the questions that you have above.

Good luck,

-Conrad

On Thu, Jun 17, 2010 at 11:27 PM, Conrad T. [email protected]
wrote:

<%= link_to_remote “XXX”,
{ :url => “/activities/hide_dock”, :update =>
“dock-container”, :complete => “fixDock()” }, { :class => “activities” }
%>

Sharkie, I would recommend reading the following first before you start
upgrading from Rails 2.x to Rails 3.x:

http://blog.peepcode.com/tutorials/2010/live-coding-rails-3-upgrade

Here’s another excellent reference that goes into greater detail of
convert from Rails 2.x to Rails 3.x:

Good luck,

-Conrad