开发者

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 rend开发者_运维技巧ers according to the princely plugin.

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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜