Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9142061
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:43:39+00:00 2026-06-17T09:43:39+00:00

How to redirect the two links to two urls by using single method in

  • 0

How to redirect the two links to two urls by using single method in controller?

Example:

def index
  @location_id = Location.find(@location_id)
  @epc = Enr::Rds::CurrentEpc.find_by_location_id(@location_id)
  if # PDF EPC link clicked
    @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
  if # LIVE EPC link clicked
    @epc = Enr::Rds::XmlData.find_by_location_id(@location_id)
    redirect_to @epc.report_url
  end
end

in my view,

<%= link_to 'PDF', enr_location_current_epc_index_path(@location) %>
<%= link_to 'LIVE', enr_location_current_epc_index_path(@location) %>

in my routes

resources :current_epc, only: [:index, :show] do
  get :download, :on => :collection
end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T09:43:40+00:00Added an answer on June 17, 2026 at 9:43 am

    I would consider create 2 differente actions. One for each case. It would make your actions and your code much easier to read.

    Then u would result with 3 actions. Index which would only load the initial objects, one to treat the specific id by the first logic and another link to treat the second logic.

    def index
      @location_id = Location.find(@location_id)
      @epc = Enr::Rds::CurrentEpc.find_by_location_id(@location_id)
    end
    
    pdf_epc
      @location_id = Location.find(@location_id)
      @epc = Enr::Rds::CurrentEpc.find_by_location_id(@location_id)
      @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
    
    def live_epc
      @epc = Enr::Rds::XmlData.find_by_location_id(@location_id)
      redirect_to @epc.report_url
    end
    

    in your routes

    resources :current_epc, only: [:index, :show] do
      get :download, :on => :collection
    end
    get "/pdf_epc/:id" => "current_epc#pdf_epc", :as => enr_location_current_epc_pdf
    get "/live_epc/:id" => "current_epc#live_epc", :as => enr_location_current_live_epc
    

    in your view

    <%= link_to 'PDF', enr_location_current_epc_pdf_path(@location) %>
    <%= link_to 'LIVE', enr_location_current_live_epc_path(@location) %>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using servlet there is two method redirect and forward both are send
i need help redirecting this two links to one link: Link #1: http://www.domain.com/index.php?til=d_news&id_new=1 Link
I'm looking at a web application with a Response.Redirect between two Https pages. I
I have a hotel with two domains. Now the customer want a redirect: domain1.dk/folder/
Iam working on Ubuntu.(Linux) I want to redirect from the page one.php to two.php,
On index.gsp I have this to redirect it to list.gsp so I'm imagining is
Basically I have two controllers using CodeIgniter for a simple blog for a project
There will be several high profile links for customers to focus on, for example:
I'm trying to redirect users of a web page to one of two different
I'm trying to make a two-step confirmation like heroku using Devise. My routes: devise_for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.