views:

15

answers:

1

Hi Everyone,

I have created a custom action within one of my controllers as follows:

  # GET /kases/discharge/1
  # GET /kases/discharge/1.xml
  def discharge
    @kase = Kase.find_by_jobno(params[:id])

    respond_to do |format|
      format.html { } # discharge.html.erb
      format.xml  { render :xml => @kase }
      format.pdf { render :layout => false }

      prawnto :prawn => { 
                 :background => "#{RAILS_ROOT}/public/images/discharge.png", 
                 :left_margin => 0, 
                 :right_margin => 0, 
                 :top_margin => 0, 
                 :bottom_margin => 0, 
                 :page_size => 'A4' }
    end

  end

For the edit actions etc the link would be

link_to edit_kase_path(@kase)

Is there a way of linking to the discharge action already, or do I have to make a custom route?

Thanks,

Danny

+1  A: 

You can add a RESTful member action. In config/routes.rb:

map.resources :kases, :member => { :discharge => :get }

This will generate a discharge_kase helper method that will invoke your discharge action.

John Topley
Superb! Thanks for your help!
dannymcc