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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T04:52:34+00:00 2026-06-08T04:52:34+00:00

In rails, I am trying to get a URL from a model into my

  • 0

In rails, I am trying to get a URL from a model into my javascript in the view as a string. This is what I do currently.

#in the model
has_attached_file :avatar, styles: { thumb: "60x60>"}, :default_url => "/system/users/avatars/thumb/missing.png"
#using paperclip gem.
....
def someMethod
   return [neares.map{|u| u.avatar.url(:thumb)}.compact]
end

Later in the view I do the following:

anArray = <%=aModelInstace.someMethod().to_json%>;

This is what I get in my rendered javascript:

//swap all the $ with &
anArray = [[$quot;/system/users/avatars/thumb/missing.png$quot;],[/* many similar to the previous */]];

This does not compile and causes an error, “unexpected token &”. So how can I get this to return an actual string in javascript, and not just with the wrapped quot signs?


I have tried u.avatar.url(:thumb).to_s and "#{u.avatar.url(:thumb)}". No luck. Also, hours of googling got me nowhere 🙁

  • 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-08T04:52:35+00:00Added an answer on June 8, 2026 at 4:52 am

    As apneadiving and Benjamin Tan said:

    Use:

    anArray = <%=raw aModelInstace.someMethod().to_json%>;

    This solved the problem.

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

Sidebar

Related Questions

I am trying to get some Javascript working in my Rails app. I want
I'm trying to get a resouce from my autocomplete.js.coffee(.erb) file. The resource's URL is
Trying to get into Rails and feedzirra! :) I have stores multiple feed urls
I'm trying to get a rails website up and running from github, and I'm
I'm trying to get the account info from Unfuddle API using ActiveResource The url
I'm trying to generate a URL for a model which is namespaced from a
I'm currently trying to get a couple of small Rails apps running on a
Trying to get my server to serve my rails apps. I have a test
I'm trying to get ruby on rails working nicely with MySQL on Mac OS
I'm trying to get rails running on my mac which is running lion. I'm

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.