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 7008737
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:46:25+00:00 2026-05-27T21:46:25+00:00

I read all the answers that popped up when I started posting this question

  • 0

I read all the answers that popped up when I started posting this question but they don’t seem to solve my issue.

I added a new action called get_results to my controller (in addition to the ones that were created via scaffolding), but every time I change the choice in the select menu, it directs me to “edit” action, not “get_results”,

This is the js

<script type="text/JavaScript">
$(function(){
  $('.menu_class').bind('change', function(){
      $.ajax('#{:controller => "my_tests", :action => "get_results"}?param_one=' + $(this).val());
  });
});
</script>

EDIT : this is the js code that worked for me, THANKS to Robin’s answer below:

<script type="text/JavaScript">
$(function(){
  $('.menu_class').bind('change', function(){
    $.ajax({
      url: "<%= get_results_my_tests_url %>",
      data: {
        param_one: $(this).val()
      }
    });
  });
});
</script>

This is the action I added (snippets)

def get_results

  # some stuff goes here

  respond_to do |format|
    if @my_test.update_attributes(params[:my_test])
      format.html
      format.js
    else
      format.html { render :action => "update" }
      format.json { render :json => @my_test.errors, :status => :unprocessable_entity }
    end
  end
end

I added a specific route for it into my routes.rb

MyTests::Application.routes.draw do

  resources :my_tests
  get "home/index"
  match '/my_tests/get_results' => 'my_tests#get_results', :as => :get_results
  match ':controller(/:action(/:id(.:format)))'
  root :to => 'home#index'
end

EDIT : this is the routes config that worked for me, THANKS to Robin’s answer below:

resources :my_tests do
  collection do
    get :get_results
  end
end

rake routes gives me this

my_tests     GET    /my_tests(.:format)                    {:action=>"index", :controller=>"my_tests"}
             POST   /my_tests(.:format)                    {:action=>"create", :controller=>"my_tests"}
new_my_test  GET    /my_tests/new(.:format)                {:action=>"new", :controller=>"my_tests"}
edit_my_test GET    /my_tests/:id/edit(.:format)           {:action=>"edit", :controller=>"my_tests"}
my_test      GET    /my_tests/:id(.:format)                {:action=>"show", :controller=>"my_tests"}
             PUT    /my_tests/:id(.:format)                {:action=>"update", :controller=>"my_tests"}
             DELETE /my_tests/:id(.:format)                {:action=>"destroy", :controller=>"my_tests"}
home_index   GET    /home/index(.:format)                  {:action=>"index", :controller=>"home"}
get_results         /my_tests/get_results(.:format)        {:action=>"get_results", :controller=>"my_tests"}
                    /:controller(/:action(/:id(.:format)))
      root          /                                      {:action=>"index", :controller=>"home"}

So why is it always directing me to “edit” action and not “get_results”?

  • 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-05-27T21:46:26+00:00Added an answer on May 27, 2026 at 9:46 pm

    Try this:

    Your javascript should be

    <script type="text/JavaScript">
        $(function(){
             $('.menu_class').bind('change', function(){
                 $.ajax({
                   url: "<%= get_results_my_tests_url %>",
                   data: {
                       param_one: $(this).val()
                   }
                 });
             });
         });
    </script>
    

    Your routes:

    resources :my_tests do
        # if "/my_tests/get_results" is really what you want
        collection do
            get :get_results
        end
        #if "/my_tests/1/get_results" is what you actually want
        #it would make more sense, especially because you have @my_test in the controller
        member do
            get :get_results
        end
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know this question has been asked before and I read all the answers
UPDATE: It seems that everyone didn't read my question thoroughly, all answers suggest me
I read this question's answers that explain the order of the LINQ to objects
I've read all the answers on to this questions and none of the solutions
I've read all recommended articles on SynchronizationContext, but there is one small question I
I have read the link that answers the question of whether there is a
I've checked google for help on this subject but all the answers keep overlooking
First of all I'd like to state that, despite the title, this question is
There are many similar questions, but nothing that answers this specifically after googling around
I have read through all the threads out there that looked as if they

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.