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

  • SEARCH
  • Home
  • 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 9224149
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T04:14:43+00:00 2026-06-18T04:14:43+00:00

I currently have a form (using form_tag). One of the fields is a dropdown

  • 0

I currently have a form (using form_tag). One of the fields is a dropdown list of options. Each option value matches the name of a method in my controller. What I want to do is when the form submit button is clicked, it runs the controller method corresponding directly to the value selected in the dropdown field.

I’ve built a work-around right now, but it feels too verbose:

def run_reports
  case params[:report_name]
    when 'method_1' then method_1
    when 'method_2' then method_2
    when 'method_3' then method_3
    when 'method_4' then method_4
    else method_1
end
# each method matches a method already defined in the controller 
# (i.e. method_1  is an existing method)

I had thought that it may work to use the dropdown option value to run the corresponding method in my controller through the form_tag action (i.e. :action => params[:report_name]), but this doesn’t work because the action in the form needs to be set before the params value is set. I don’t want to use javascript for this functionality.

Here is my form:

<%= form_tag("../reports/run_reports", :method => "get") do %>
  <%= select_tag :report_name, options_for_select([['--  Please Select  --',nil],['Option 1','method_1'], ['Option 2','method_2'], ['Option 3','method_3'], ['Option 4','method_4']]) %>
  <%= submit_tag "Run Report" %>
<% end %>

Any suggestions?

Can I change my controller method to look something like this – but to actually call the controller method to run? I’m guessing this won’t run because the params value is returned as a string…

def run_reports
  params[:report_name]
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-18T04:14:45+00:00Added an answer on June 18, 2026 at 4:14 am

    WARNING: this is a terrible idea

    You could call the method via a snippet of code like this in the controller:

    send(params[:report_name].to_sym)
    

    The reason this is a terrible idea is that anyone accessing the page could manually construct a request to call any method at all by injecting a request to call something hazardous. You really, really do not want to do this. You’re better off setting up something to dynamically call known, trusted methods in your form.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am developing a web form using Visual Web Developer Currently I have class
I currently have a form with inputs and name attributes. I'm able to get
I currently have form that checks if a user has unsubmitted changes when they
We currently have a form with the standard multi-select functionality of here are the
I currently have a simple form that when you click the save button will
I currently have a web form aspx page that calls RegisterClientScriptBlock. This sends down
I currently have a PHP form that uses AJAX to connect to MySQL and
I currently have a datasource from a client in the form of XML, this
I currently have this useful code that I found elsewhere on StackOverflow: form.DrawToBitmap(bmp, new
I currently have this as a search: <%= form_tag users_path, :controller => 'users', :action

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.