I am facing an issue while trying to use a JavaScript function through the Chrome Console after embedding that function within the Rails Asset Pipeline Manifest. To achieve this, I followed these steps to create and set up a basic Rails 4.2.4 App:
$ rails new JavascriptExample
$ cd JavascriptExample
$ rails g scaffold Bear name:string
$ rake db:migrate
Next, I made changes in the
app/assets/javascripts/bears.coffee
file by adding a console log statement and defining a function as shown below:
console.log("asset pipeline sucks")
square = (x) -> x * x
After making these changes, I started the server using the following command:
$ rails s
Upon visiting localhost:3000/bears
, I noticed that my console log statement worked fine. However, when I tried running the square(5);
command in the console, it threw an error stating
Uncaught ReferenceError: square is not defined(…)
.
My question is, why am I unable to execute the function in this manner even though it is clearly loaded into application.js
?