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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T15:31:56+00:00 2026-06-14T15:31:56+00:00

I have a form with 2 inputs and button. An user put feed url

  • 0

I have a form with 2 inputs and button. An user put feed url in the first input and press the button:

<%= link_to "get name", { :controller => 'Feeds', :action => "get_title" }, 
:remote => true, :class=>'btn btn-mini' %>       

Here is controller method

def get_title
   respond_to do | format |  
       format.js {render :layout => false}  
   end
end

And here is a get_title.js.erb:

var url = $( "#feed_url" ).val();
console.log(url);
$( "#feed_name" ).val("<%= @proxy.title(url) %>");

I get value of the first input and want to pass it as parameter to Ruby class. But in this case I get the error:

ActionView::Template::Error (undefined local variable or method `url' for #<#<Class:0x41ec170>:0x41ef968>):
    1: var url = $( "#feed_url" ).val();
    2: console.log(url);
    3: $( "#feed_name" ).val("<%= @proxy.title(url) %>");

Rails this that ‘url’ is a Ruby variable, but not JS one.

How can I pass JS variable to Ruby code ?

Thanks in advance.

  • 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-14T15:31:57+00:00Added an answer on June 14, 2026 at 3:31 pm

    Remember that any ERB (ruby) code is executed server side, while Javascript is, of course, rendered client side. As a result, your line <%= @proxy.title(url) %> is rendered WAY before that url value is ever evaluated. The solution to your situation is more along the lines of passing data to Rails, and rendering the response. Three things to facilitate this (bearing in mind that this is only one approach, and I’m sure there are plenty of others, and possibly better ways of doing this):

    1- Your link_to won’t post the user-input URL value because it is not POSTing the form. Instead, change the surrounding form to use :remote=true, and use a typical form.submit button rather than this link. Your form with the URL value will be submitted (and it will be asynchronous).

    2- In your controller, render your title like you were trying to do, doing something along these lines:

    def get_title
        render :text=>@proxy.title(params[:url])
    end
    

    3- Bind to the ajax:success event, something along these lines:

    $("form#myForm").bind("ajax:success", function(event, data, status, xhr){
        $( "#feed_name" ).val(data) // data, in this case, is the rendered `@proxy.title(url)` we did in step 2.
    })
    

    Hope that makes sense. Let me know if it does not.

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

Sidebar

Related Questions

I have a windows form application where a user inputs their name (First and
I have a form with inputs, the Jquery makes a specific input (the url
I currently have a form with inputs and name attributes. I'm able to get
I have a form that I want a user to put in their name
I have a form with input fields and a button which fades in when
I have a form with an input textbox and a button. When I click
I have a basic form with a search input and a submit button within.
I have... a dynamic populated select box several input boxes a submit button form
I have two buttons on my MVC form: <input name=submit type=submit id=submit value=Save />
Here's the problem. I have a form with various inputs and a submit button.

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.