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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:20:36+00:00 2026-06-13T23:20:36+00:00

I am updating a simple text_area in Rails using Ajax: application.js : $(#invoice_project_id).change(function() {

  • 0

I am updating a simple text_area in Rails using Ajax:

application.js:

$("#invoice_project_id").change(function() {
    var value=$(this).val();
    $.get('/invoices/get_recipient', {project_id= : value}  function(response) {
        $('#invoice_recipient').val(response);
    })
});​

get_recipient.js:

$('#invoice_recipient').val("<%= @recipient.to_s.gsub!(/\n/, '\n') %>");

invoices_controller.rb:

def get_recipient
  project = Project.find(params[:project_id])
  @recipient = project.person.address
end

The code works great and replaces the value of the recipient text_area with the correct address, depending on what project gets chosen in the select menu.

The problem is that it works only with the addresses that already exist in the database. (I am using the Rails Faker gem to populate my database.) The moment I re-save a person‘s address manually in my Safari browser, the text_area won’t get updated through Ajax anymore when I try to do so using the above code.

How is this possible?

I am already escaping the newline characters using the gsub! method above, so I can’t think of anything else I could do.

Can anybody help?

Thanks…

  • 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-13T23:20:36+00:00Added an answer on June 13, 2026 at 11:20 pm

    OK, turns out that the carriage returns in the addresses were causing the trouble.

    These carriage returns are only created when updating an address in the browser through a textarea. The Faker gem mentioned above creates newline characters but no carriage returns.

    I saw this only when inspecting my database records on the console because \r and \n characters are invisible anywhere else I looked.

    So in my particular case I just needed to remove the carriage returns in my model like so:

    address.gsub!("\r", "")
    

    I was not able to do this in any of my javascript files.

    Just one simple line of code, but several hours of work for me. So hopefully somebody else will benefit from this.

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

Sidebar

Related Questions

I am creating a simple application in JSP- JDBC for inserting and updating details
Every time this tab get loaded instead of updating the dynamic label, it writes
I'm updating my user's Twitter status using the simple code below. My problem is
Yeah this is a pretty simple topic, but my form just isn't updating the
I have the simple JS code for updating text on button: <html> <head> <script
When updating a DataTable with 1850-ish new rows to a FbDataAdapter I get a
I have written a simple stored procedure for updating a record which isn't working
I wrote a simple WinForm program in C# that displays the time, updating every
I'm having problems updating a div's content in IE using .update; I also tried
I have a very simple StopWatch application in Silverlight. I have the following private

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.