Rendering a partial on a two column page

Hi,

I attached a page for clarity of what I want.

I have a two column page (index.html.erb). On the left hand side, I have
the order ID and order NAME displayed. There is a SHOW link next to each
entry.

I want to be able to click on the SHOW link and have it display the full
order information on the right hand column (this is the show.html.erb
file that Rails generated). I turned the default Rails generated
show.html.erb file into a partial.

I’m sure this has to use link_to_remote on the SHOW link, but I’m not
sure how to make it update the right hand column with the partial. I’ve
read through a lot of the Rails API info jumping around to Helpers,
remote_function and other things. I’m sure I’m missing something simple.

Any help would be appreciated.

Okay, I made a really dumb mistake and put:

<% javascript_include_tag ‘defaults’ %>

Instead of:

<% javascript_include_tag :defaults %>

So that fixed my rendering. At least I’m getting information over to the
other column now. But it’s an error, because it can’t find the ID. I
attached the screenshot of the error I’m seeing. The following will be
the code I currently have pertaining to this function. If anyone has any
ideas on why it’s throwing that error, I would really appreciate it (I
know I’m missing something small here).

Here is my Show action in the Controller:

def show
@order = Order.find(params[:id])

respond_to do |format|
  format.html # show.html.erb
  format.xml  { render :xml => @order }

end

end


Here’s the sections I have in my index.html.erb file:

  <% @orders.each do |order| %>
    <tr>
      <td><%=h order.id %></td>
      <td><%=h order.name %></td>
      <td><%= link_to_remote "Show", :url => {:controller => 

‘orders’, :action => ‘show’}, :update => “order_div”, :method => ‘get’
%>

<% end %>


Here is the info in the _order_show.html.erb partial:

Name: <%=h @order.name %>

Address: <%=h @order.address %>

City: <%=h @order.city %>

State: <%=h @order.state %>

Zip: <%=h @order.zip %>

…ETC

On May 20, 2010, at 5:01 PM, Matt R. wrote:

other column now. But it’s an error, because it can’t find the ID. I

 <% @orders.each do |order| %>
   <tr>
     <td><%=h order.id %></td>
     <td><%=h order.name %></td>
     <td><%= link_to_remote "Show", :url => {:controller =>

‘orders’, :action => ‘show’,

:id => order.id

Address:
<%=h @order.state %>
http://www.ruby-forum.com/attachment/4747/ScreenShot004.jpg

But you could also use a named route for the url. Something like
order_path(order)

-Rob

Rob B.
http://agileconsultingllc.com
[email protected]

[email protected]

Rob B. wrote:

Hi Rob,

Thanks for the quick response!

I’m sorry, I’m still relatively new at this Rails stuff. I have gone
through a couple of books, but it’s hard to tie it all together. :slight_smile:

When you put the following:

:id => order.id

Where should I enter that? Within the link_to_remote somewhere?

Also, I would like to know the following. Not sure where I would enter
that path in the link_to_remote:

But you could also use a named route for the url. Something like
order_path(order)

Thanks again! I need all the help I can get. :slight_smile:

On May 20, 2010, at 5:45 PM, Matt R. wrote:

:id => order.id

Where should I enter that? Within the link_to_remote somewhere?

Yes, right where I put it:

    <td><%= link_to_remote "Show", :url => {:controller =>

‘orders’, :action => ‘show’,

:id => order.id

}, :update => “order_div”, :method => ‘get’
%>

Also, I would like to know the following. Not sure where I would enter
that path in the link_to_remote:

But you could also use a named route for the url. Something like
order_path(order)

Thanks again! I need all the help I can get. :slight_smile:

<%= link_to_remote("Show", :url => order_path(order), :update => "order_div", :method => 'get') %>

-Rob

Rob B.
http://agileconsultingllc.com
[email protected]

[email protected]

Thanks Rob!!! It worked PERFECTLY. Thanks again for you help!