开发者

Rails address and routes?

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)
开发者_StackOverflow社区

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

Thanks,

Danny


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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜