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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T20:21:59+00:00 2026-06-01T20:21:59+00:00

In my assets, I have a file called maps.js.erb , basically with only the

  • 0

In my assets, I have a file called maps.js.erb, basically with only the following (debugging) content:

alert("<%= @map.width %>");

This JS file is loaded through the show.html.erb view belonging to maps.

<%= javascript_include_tag params[:controller] %>
<h1><%= @map.title %></h1>
…

The HTML file itself shows the map’s title, e.g. when browsing to /maps/1/, since @map is defined in the controller. However, as soon as I include the JS file, I get the following error:

NoMethodError in Maps#show

Showing …/app/views/maps/show.html.erb where line #1 raised:

undefined method ‘title’ for nil:NilClass
(in …/app/assets/javascripts/maps.js.erb)

  • Why is @map not available in the js.erb file?
  • How else can I access this instance variable defined in my controller?
  • 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-01T20:22:00+00:00Added an answer on June 1, 2026 at 8:22 pm

    Ryan Bates did a screencast right on that topic – you might wanna check it out:

    http://railscasts.com/episodes/324-passing-data-to-javascript


    In the html.erb file, you can define the variables:

    <%= javascript_tag do %>
      window.productsURL = "<%=j products_url %>";
      window.products = <%=raw Product.limit(10).to_json %>;
    <% end %>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a file called myjavascript.js.erb in my assets path. This is where I
Say I have a file in my kohana 3 website called assets/somefile.jpg . I
I have file in Assets and I need to write this file to the
I want to delete a file in assets folder in run-time. I have a
Please help me with following problem. In my android assets folder I have xml
I have this method call I have to use... financial_document.assets.length But financial_document.assets could be
I have a .coffeescript.erb file in which I would like to get CSRF meta-tag
So, I have an app/assets/stylesheets/ directory structure that looks something like this: |-dialogs |-mixins
I have two Flash files: pre-loader and application. Pre-loader: (D:\Projects\FlashApps\dd\edd.fla) is doing basically this:
I have a WebView. I want to load a local HTML file called helloworld.html.

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.