small medium large xlarge

Me-new-3_pragsmall
16 Jun 2010, 23:41
Aston J (18 posts)

Is the link_to help missing here in the wiki? I can’t find it and I’m stuck :(

Samr_small_pragsmall
17 Jun 2010, 11:32
Sam Ruby (634 posts)

The wiki has not been updated yet.

Take a look at the usages of link_to on page 44 and 85. In particular, look at the link_to ‘Edit’ and ‘Destroy’ on the second page.

The documentation for link_to is available online. As applies here:

# The first parameter is what you want displayed on the screen. In this case, you will want to use the image_tag that already is present in app/views/store/index.html.erb. # The second parameter contains the target of the link. Use the same value for this link as is used on the call to button_to later in app/views/store/index.html.erb. # The third parameter is the html options. You will want to specify :method => :post here.

Me-new-3_pragsmall
17 Jun 2010, 13:10
Aston J (18 posts)

Thanks for the reply Sam.

That was something I tried:

<%= link_to image_tag(product.image_url), line_items_path(:product_id => product), :method => :post %>

But when you click on the image to add to cart, it goes to the line_items listing page, and not the ‘Your Progmatic Cart’ page.

Have I missed something out? :-/

Samr_small_pragsmall
17 Jun 2010, 17:50
Sam Ruby (634 posts)

Very puzzling. From those symptoms, the :method => :post is being ignored. As the default is :get you are directed to the line items listing page.

Here’s what works on my machine, but I can’t see any difference (other than spacing) from what you tried:

<%= link_to image_tag(product.image_url),
  line_items_path(:product_id => product), :method=>:post %>
Me-new-3_pragsmall
17 Jun 2010, 20:32
Aston J (18 posts)

That gives me the same thing Sam :-/

I’m running Ruby 1.8.7 and Rails 3 beta 3.

I can’t seem to upgrade to beta4 (I get ‘file not found: lib’ :-/) could that be the issue?

(I’m running Snow Leopard)

Generic-user-small
19 Jun 2010, 17:30
Alex V (5 posts)

Same problem here - the POST does not work.

Generic-user-small
19 Jun 2010, 17:38
Alex V (5 posts)

Same thing on Beta4! =(

Generic-user-small
19 Jun 2010, 20:54
Alex V (5 posts)

Okay. Solved. The previous versions of the book, on page 106-107, did not include the call for “<%= javascript_include_tag :defaults %>”. This is also not included in the relevant “depot_e” file of ZIP that comes along with the book.

In other words: anyone who was following the book bottom-up, would get stumped like Aston and I did.

Me-new-3_pragsmall
19 Jun 2010, 21:45
Aston J (18 posts)

Nice one Alex!

So for anyone following, you need to add:

<%= javascript_include_tag :defaults %>

to the file:

views/layouts/application.html.erb

As on page 107

You must be logged in to comment