ruby-on-railspdfpdf-generationprincely

Assistance using respond_to to find the right actions to render PDF in ruby on rails


I am trying out Prince with the Princely plugin, which is supposed to format templates that have the .pdf into a PDF generator.

Here is my controller:

class TodoController < ApplicationController

  def show_date
    @date = Date.today

    @campaigns = Campaign.all

    @contacts = Contact.all

    @contacts.each do |contact|

    end

    respond_to do |format|
      format.html
      format.pdf do
        render :pdf => "filename", :stylesheets => ["application", "prince"], :layout => "pdf"
      end
    end
  end

end

I changed the routes.db to include the following:

map.connect ':controller/:action.:format'

  map.todo "todo/today",
            :controller => "todo",
            :action => "show_date"

My expected behavior is when I enter todo/today.pdf, it tries to execute show_date, but renders according to the princely plugin.

Right now, it says cannot find action. What do I need to do to fix this?


Solution

  • You need to move the default route line (the first map.connect) below the map.todo line.

    routes.rb is matching the first rule and looking for a today action.