0

I am following a tutorial from railscast (http://railscasts.com/episodes/220-pdfkit) and have become stuck when trying to implement the link for a PDF. The original code was:

<p id="pdf_link"><%= link_to "Download Invoice (PDF)", order_path(@order, :format => "pdf") %></p>

I am however using haml so I have edited the line as follows:

= link_to 'Download PDF', order_path(@order, :format => "pdf")

I have realised that order_path would relate to a route specified in routes.rb. The problem is my application does not have a route folder (inherited the application from another developer). Therefore how would i go about creating this path in haml code.

Also I was wondering about replacing @order. In looking through the code i noticed it is declared as such. Could someone explain what this piece of code declares order as?

@order = Order.find(params[:id])
user3385136
  • 513
  • 1
  • 7
  • 20
  • Is this a Rails question or a Sinatra question? Sinatra doesn’t have `link_to` and `_path` methods by itself. – matt Sep 16 '15 at 15:43
  • @matt I'm not quite sure. This application is strange it has references to Sinatra but link_to etc works in it so you tell me is it Rails or Sinatra or can it be both? – user3385136 Sep 16 '15 at 16:44
  • Is it [Padrino](http://www.padrinorb.com/) perhaps? – matt Sep 16 '15 at 16:50
  • I think it may well be. It really confuses me that there are references to all three within the code so I'm never 100% sure. – user3385136 Sep 16 '15 at 16:55

1 Answers1

2

Routes, in Rails, are declared in the config/routes.rb file. Take a look ate this guide for more info.

The order_path is a helper method that rails provide to you when you declare your routes. You can see these routes aliases by runnig the rake routes command in your application root folder.

Regarding to this line:

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

This will try to get an Order from the database using the passed id in the request parameters. See this guide for more information.

My advise, read the entire Rails Guide so you know what are you dealing with.

lcguida
  • 3,787
  • 2
  • 33
  • 56