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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T11:07:54+00:00 2026-06-11T11:07:54+00:00

I have a Ruby method nested inside a jQuery onclick event and I want

  • 0

I have a Ruby method nested inside a jQuery onclick event and I want the method to execute when the div is clicked. This works; however, the method is also executing on page refresh. Why does it also execute on page refresh and is there any way to limit it to only onclick?

 $(function() { 
   $('.myDiv').click(function(){
      <% foo_bar %>
   });
 });
  • 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-11T11:07:55+00:00Added an answer on June 11, 2026 at 11:07 am

    I don’t see how foo_bar can be executed when you click on the div. Ruby is executed server side, jQuery is executed client side. You cannot execute ruby code from your client.
    Your foo_bar is executed on refresh page because the server need to interpret it to give it’s result into the <% %> tag. However, when you click on the div, nothing will happen because the jquery function will be empty (since you did not write <%= %>). Even if you wrote <%= %>, the jQuery would only execute the foo_bar result, not the function itself.

    Maybe you could explain what you want to do in your foo_bar. If you want interact with the server, you will need something like Ajax.

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

Sidebar

Related Questions

I have a ruby method (deactivate!) that is on an activeRecord class. However, I
If I have Foo::Bar written in Ruby, and I want to add a method
I have some data inside this variable and I want to know how could
I have a Ruby method that searches an array of hashes and returns a
In Ruby on Rails, I have an update method in a controller, that is
I have some difficulties for using Ruby block, passing in a method. As in
I am using Ruby on Rails 3.2.2 and MySQL. I have a method (an
In Rails 3.0.9 (Ruby 1.9.2, MySQL) I have a method that is supposed to
Possible Duplicate: Why do this Ruby object have two to_s and inspect methods that
When trying to deal with a nested hash in ruby, I'm getting this error:

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.