def pdf_url
if (params[:url] == 1)
do something
else
do something else
end
@epc = Enr::Rds::CurrentEpc.find_by_location_id(@location_id)
if @epc != nil
@epc.current_epc_path[-4..-1] == '.pdf'
content = open(@epc.current_epc_path, "rb") {|io| io.read }
send_data content, :filename => 'epc.pdf', :disposition => 'inline'
end
end
In your routes.rb:
match "/anything/pdf_url/:url" => "anything#pdf_url"
And your two links:
<%= link_to "first", "/anything/pdf_url/1" %>
<%= link_to "second", "/anything/pdf_url/2" %>
EDIT:
member is used when it requires an :id parameter, if not it is a collection. Anyway, I would use match in that case like (which is in parenthesis is optional):
match "/anything(/download/:url)" => "anything#index"
and get the parameter in your controller like this:
def index
if params[:url] == 1 # Or whatever you put in your link_to
# redirect_to url
else
# redirect_to url
end
end
EDIT 2:
Index controller:
def index
if params[:id]
@location_id = Location.find(params[:id])
@epc = Enr::Rds::CurrentEpc.find_by_location_id(@location_id)
if params[:url] == 'pdf'
@epc.current_epc_path[-4..-1] == '.pdf'
content = open(@epc.current_epc_path, "rb") {|io| io.read }
send_data content, :filename => 'epc.pdf', :disposition => 'inline'
elsif params[:url] == 'live'
@epc = Enr::Rds::XmlData.find_by_location_id(@location_id)
redirect_to @epc.report_url
end
else
@locations = Location.all
respond_to do |format|
format.html
format.json { render :json => @locations }
end
end
end
Your routes:
match "/anything(/:id(/:url))" => "anything#index"
Your view (change links to fit your tastes, it's just a simple example):
<%= link_to "first", "/anything/1/pdf" %>
<%= link_to "second", "/anything/1/live" %>