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
あなたの routes.rb で:
match "/anything/pdf_url/:url" => "anything#pdf_url"
そしてあなたの2つのリンク:
<%= link_to "first", "/anything/pdf_url/1" %>
<%= link_to "second", "/anything/pdf_url/2" %>
EDIT: member は、:id パラメータが必要な場合に使用されます。そうでない場合は、コレクションです。とにかく、その場合は次のように match を使用します(括弧内はオプションです):
match "/anything(/download/:url)" => "anything#index"
次のようにコントローラーでパラメーターを取得します。
def index
if params[:url] == 1 # Or whatever you put in your link_to
# redirect_to url
else
# redirect_to url
end
end
編集 2: インデックス コントローラー:
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
あなたのルート:
match "/anything(/:id(/:url))" => "anything#index"
あなたの見解(好みに合わせてリンクを変更してください。これは単なる例です):
<%= link_to "first", "/anything/1/pdf" %>
<%= link_to "second", "/anything/1/live" %>