# Link\_to\_remote the right way in Rails 3.0?

**URL:** <https://www.ruby-forum.com/t/link-to-remote-the-right-way-in-rails-3-0/190346>\
**Category:** Rails\
**Created:** [June 18, 2010, 6:51am UTC](https://www.ruby-forum.com/t/link-to-remote-the-right-way-in-rails-3-0/190346 "2010-06-18T06:51:57Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sharkie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/58f4c7/32.png) [@sharkie](https://www.ruby-forum.com/u/sharkie)\
**Post date:** [June 18, 2010, 6:51am UTC](https://www.ruby-forum.com/t/link-to-remote-the-right-way-in-rails-3-0/190346/1 "2010-06-18T06:51:57Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![sharkie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/58f4c7/32.png) [@sharkie](https://www.ruby-forum.com/u/sharkie)\
**Post date:** [June 18, 2010, 8:28am UTC](https://www.ruby-forum.com/t/link-to-remote-the-right-way-in-rails-3-0/190346/2 "2010-06-18T08:28:27Z")

</div>

On Thu, Jun 17, 2010 at 9:51 PM, Sharkie L.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)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](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:

> **[GitHub - rails/jquery-ujs: Ruby on Rails unobtrusive scripting adapter for...](https://github.com/rails/jquery-ujs)**
>
> Ruby on Rails unobtrusive scripting adapter for jQuery - GitHub - rails/jquery-ujs: Ruby on Rails unobtrusive scripting adapter for jQuery

> 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](http://pragprog.com) for  
additional  
information regarding the questions that you have above.

Good luck,

-Conrad

---

<div class="post-metadata">

**Author:** ![sharkie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/58f4c7/32.png) [@sharkie](https://www.ruby-forum.com/u/sharkie)\
**Post date:** [June 18, 2010, 8:30am UTC](https://www.ruby-forum.com/t/link-to-remote-the-right-way-in-rails-3-0/190346/3 "2010-06-18T08:30:48Z")

</div>

On Thu, Jun 17, 2010 at 11:27 PM, Conrad T. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
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](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:

> **[加速器ios免费|免费加速器](https://www.railsupgradehandbook.com)**
>
> 加速器ios免费成立于2002年7月，是一家壹级劳务分包企业，公司管理机制完善，技术力量雄厚，具备了模板工、木工、钢筋工、抹灰工、瓦工、架子工、混凝土工、水电暖工为一体的专业综合施工能力。以建设厂房、综合楼、高层住宅为主

Good luck,

-Conrad
