bennett_an
bennett_an

Reputation: 1708

no route matches

I have a file reports/print.html.erb

in reports_controller

def print
  @report = Report.find(params[:id])

  respond_to do |format|
    format.html { render :layout => false }
    format.xml  { render :xml => @report }
  end
end

in routes.rb

match 'reports/print(:id)' 

trying to call with

<%= link_to 'Print', report_print_path(:id => @report.id), :method => :put %>

and getting this error:

ActionController::RoutingError in Reports#show
No route matches {:action=>"print", :id=>23, :controller=>"report"}

Where am I going wrong?

Upvotes: 0

Views: 409

Answers (2)

bennett_an
bennett_an

Reputation: 1708

made it work with

<%= link_to 'Print', print_url(:id => @report.id) %>

and

match 'print/(:id)' => 'reports#print', :via => :get, :as => :print

No idea why it was giving me problems, there's 4 hours of my life i'll never get back.

Upvotes: 0

Francisco Soto
Francisco Soto

Reputation: 10392

Change your route to:

match 'reports/print/:id' => 'controller#print', :via => :put

That may fix it (didn't test the code though, and change the 'controller#print' part to your actual controller name.

Upvotes: 1

Related Questions