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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:45:33+00:00 2026-06-13T12:45:33+00:00

I want to make a ruby function called within rails. I followed this question

  • 0

I want to make a ruby function called within rails. I followed this question, but I get redirected to

http://localhost:3000/my_func?arg=arg

which I don’t want. I only want to execute the function when the button is clicked, but remain on the same page!

EDIT:

I modified the code, or better yet, made a scratch site just to solve this. I only did:

rails new eraseme
cd eraseme
rails g controller public home

app/controllers/public/home.html.erb

class PublicController < ApplicationController
  def home
  end

  def my_func

  end
end

app/views/public/home.html.erb

<%= button_to "Button", {:action => "my_func", :arg => "arg"} %>

What I want to do, is execute my_func when I click the button. But when I click, I get

No route matches {:action=>"my_func", :arg=>"arg", :controller=>"public"}
  • 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-13T12:45:34+00:00Added an answer on June 13, 2026 at 12:45 pm

    So, from what I can tell. I think you want to make a button that will send an AJAX/HTTP request to the Controller in order to call a function, that won’t return a HTML file at completion.

    In order to accomplish this, you must do the following.

    1.) Set the HTTP routing for this call, this is within the config/routes.rb file.

    match '/public/my_func' => 'public#my_func'
    

    This allows your application to direct any HTTP requests with the following URL to call your method within the controller. Your button_to method will send this call with that URL due to the :action => “my_func” param.

    2.) Also include the :remote => true, :form => { “data-type” => “json” } as more parameters to the button_to method.

    This will transform the button from a traditonal HTTP request to an HTTP Request via AJAX request.

    Let me know how this works, I think there are alternatives to using AJAX in this case, if its a very simple method then you can perhaps include it within the view as erb.

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

Sidebar

Related Questions

I'm following this tutorial http://ruby.railstutorial.org/ruby-on-rails-tutorial-book My question is, what is the relation for user
I want to make a development server for Ruby. (I have done this for
I want to make apache2 run ruby scripts. I managed to do this by
I wrote a program in Ruby but I want to make an executable file
I am busy making a ruby on rails app. I want to make an
I want to make a command-line utility in ruby that when run, list the
I want to make a window manager in either of these languages (Preferably ruby).
So all I simply want to do is make a Ruby program that reads
A first look I thought erb accepts any Ruby code, but I've got this
I am quite new to ruby on rails, but I find it phantastic. Anyway,

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.