Forum: Ruby on Rails Rails 3 link_to :remote

Ad2f5c17fced8749575c2a8d40a11eba?d=identicon&s=25 Matt Royer (chuybakah)
on 2010-06-14 22:44
I recently moved to Rails 3 and am still getting used to some of its new
ways of working.

I have the following code:

----

<%= link_to "#{order.name}", :url => {:controller => 'orders', :action
=> 'show', :id => order.id }, :update => "order_div", :method => 'get',
:remote => true %>

----

I know I'm probably just missing something simple, but I'm not sure what
it is. I have my javascript included in the application.html.erb file.

This code (excluding the :remote => true) works under Rails 2.3.8 when
using link_to remote. I don't know what the new arguments require. And
after searching around for exactly what I want this to do, I couldn't
find anything.

All I want it to do is show the order information in a DIV I named:
order_div

So instead of the 'show' action moving me to the /orders/show/etc... I
want it to display the info that show normally would in the same page. I
have a list of orders to click on. Want this to happen without a full
page refresh.

Can anyone help me with the new way Rails handles this sort of thing?

Thanks,

--Matt Royer
Ad2f5c17fced8749575c2a8d40a11eba?d=identicon&s=25 Matt Royer (chuybakah)
on 2010-06-15 16:27
I wasn't sure if this was the right way to accomplish this:

----

format.js {
  render :update do |page|
    page.replace_html 'order_div', :partial => 'show_order'
  end
}

----

Apperently not, as it doesn't work. But can someone at least tell me if
I am on the right track? I've checked everywhere I can think of for a
solution to this. If anyone has any other resources to check out, please
let me know.
Ad2f5c17fced8749575c2a8d40a11eba?d=identicon&s=25 Matt Royer (chuybakah)
on 2010-06-15 16:30
Matt Royer wrote:
> I wasn't sure if this was the right way to accomplish this:
>
> ----
>
> format.js {
>   render :update do |page|
>     page.replace_html 'order_div', :partial => 'show_order'
>   end
> }
>
> ----

Sorry, forgot to say that this is in my index action of my orders
controller. Thanks.

--Matt Royer
Ad2f5c17fced8749575c2a8d40a11eba?d=identicon&s=25 Matt Royer (chuybakah)
on 2010-06-16 17:36
Update for anyone that needs help in this area. I found my problem. You
might have to do the same (if you are using this function the way I am).

In my controller, I don't know why I put this in the Index action
before. It is now in the SHOW (duh) action:

----
format.js {
  render(:update) {|page| page.replace_html 'order_div', :partial =>
'orders/order_show'}
}
----

I took out all of the other junk in my "link_to" in the view and only
have this now:

----
<%= link_to "#{order.name}", order, :remote => true %>
----

So I have a list of orders in a column on the left side of the screen.
There is a right border separating it and the right column. When I click
on one of the orders, it shows the order info in the right column.
Exactly what I wanted. Piece of cake now that I think about it.

Enjoy!
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.