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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T17:39:18+00:00 2026-05-31T17:39:18+00:00

I am currently trying to build a little widget that will retrieve a list

  • 0

I am currently trying to build a little widget that will retrieve a list of artists based on a username.

The Ruby method requires a username parameter after which an API call is made that retrieves the actual array of strings.

The web page has an input field where the user can fill out his/her username. My goal is to immediately call the ruby method and display the list of artists. My problem is being able to use the actual form input as the parameter. I figured this would be relatively easy with params[:user], in the same way it’s done in a Sinatra post method. Alas, turns out it isn’t.

I tried both a JS approach and directly calling the method after :onkeyup.

Javascript:

userChanged = function() {                  
    var user = document.getElementById("username");
    if (user.value.length != 0){                
    artists = #{RFCore::get_artists(:name => params[:user]).to_json};
    art_list.innerHTML = artists
    };
};

:onkeyup

:onkeyup => "art_list.innerHTML = #{RFCore::get_artists(:name => params[:user])[0]}"

I have substituted params[:user] with all variations I could think of such as “#{user}” and user.

The errors returned are undefined method []' for params[:user] and undefined local variable or methoduser’ for “#{user}” and user.

Perhaps there is an easy solution to this; but the feeling is starting to creep up on me my approach is wrong to begin with. I am open to any other way of achieving this.

  • 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-31T17:39:19+00:00Added an answer on May 31, 2026 at 5:39 pm

    As far as I understood, you are generating that JavaScript dynamically. So when your Ruby code produces it, it evaluates that RFCore::get_artists expression when you are generating the JavaScript code, not when the user interacts with the web page.

    If that’s the case, I recommend:

    1. Use jQuery. It makes your life much easier.
    2. When there’s some user interaction (e.g., a key press), use Ajax to communicate with your server to get back a list of artists.

    Here is a small Sinatra application that demonstrates this approach:

    require 'sinatra'
    
    get '/' do
      <<html
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
    <script type="text/javascript">
    function userChanged()
    {
      $.get('/get-artists',
            {username: $('#username').val()},
            function(data){
              $('#artists').html(data);
            });
    }
    </script>
    User: <input id="username" type="text">
    <button onclick="userChanged();">Look up</button>
    <div id="artists"/>
    html
    end
    
    get '/get-artists' do
      "Generate here list for user #{params[:username]}"
    end
    

    Please notice that the above code is just an example. The HTML generated is all wrong, no template language is being used, etc.

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

Sidebar

Related Questions

I am currently trying to build a cakephp app that will list items from
i am currently trying to build a little webapp that uses Spring, Hibernate and
I'm currently trying to build a C++ library (DLL file) that interfaces with a
I'm currently trying to build an application that inherently needs good time synchronization across
Im currently trying to build a Fluent Interface for a ServiceLocator. To ensure that
I'm currently trying to build an authentication application in Android which stores users' username
I am currently trying to build a small system that read's in a bunch
I'm currently trying to build a more or less complete set of unit tests
I am currently trying to build a very basic serial shell with my arduino.
I'm currently trying to build a RDP client in python and I came across

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.