Firstly I'm still busy learning RoR so my understanding is limited. I created a new simple project and generated my first scaffold named 'Person'. When I start up my WEBrick server I go to localhost:3000/people I get the following runtime error:
ExecJS::RuntimeError in People#index
Showing C:/Users/Dean/Desktop/guestbook/app/views/layouts/application.html.erb where line #6 raised:
(in C:/Users/Dean/Desktop/guestbook/app/assets/javascripts/people.js.coffee)
Extracted source (around line #6):
3: <head>
4: <title>Guestbook</title>
5: <%= stylesheet_link_tag "application", :media => "all" %>
6: <%= javascript_include_tag "application" %>
7: <%= csrf_meta_tags %>
8: </head>
9: <body>
If any more clarification is needed please let me know and I'll gladly update my question.
I'm no expert but it looks like it's something to do with.. the coffeescript gem? I'm really just spitballin' here... Thanks in advance!
people.js.coffee:
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
ExecJS::RuntimeErrors are typically caused by syntax errors in your coffeescript. Check your people.js.coffee file around line 6 and make sure it is syntactically correct. If you are relatively unfamiliar with coffeescript, http://js2coffee.org/ converts between JS and coffee and might be helpful. .js.coffee files will only accept coffeescript.
Related
Everything is working perfectly locally but when I tried to put the app live I've got this error:
Showing /home/rails/app/views/layouts/application.html.erb where line #9 raised:
end of file reached
(in /home/rails/app/assets/stylesheets/global.css.scss)
this is line 9
<%= stylesheet_link_tag "application" %>
when I remove this line I get errors for javascript:
<%= javascript_include_tag "vendor/modernizr" %>
What is the issue and how can it be fixed?
Also not sure about the "end of file reached global.css.scss?"
below is this:
app/views/layouts/application.html.erb:9:in `_app_views_layouts_application_html_erb__92412405316489023_40891780'
app/controllers/site_controller.rb:42:in `index'
On line 42 is the word "render"
def index
render
end
Many thanks
It should have something to do with precompile. Try cleaning the asset precompile temp folder.
If that doesn't solve it, pl post the stack trace.
When I 'rails server' the localhost:3000 works in my browser (chrome). Here's the term:
tom#toms-ubuntu:~/rails_projects/routesapp$ rails s
=> Booting WEBrick
=> Rails 3.2.16 application starting in development on http://localhost:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
[2016-01-12 10:56:27] INFO WEBrick 1.3.1
[2016-01-12 10:56:27] INFO ruby 1.9.3 (2013-11-22) [x86_64-linux]
[2016-01-12 10:56:27] INFO WEBrick::HTTPServer#start: pid=4751 port=3000
But for localhost:3000/page/home the browser displays:
NoMethodError in Page#home
Showing /home/tom/rails_projects/routesapp/app/views/layouts/application.html.erb where line #5 raised:
undefined method `[]' for nil:NilClass
Extracted source (around line #5):
2: <html>
3: <head>
4: <title>Routesapp</title>
5: <%= stylesheet_link_tag "application", :media => "all" %>
6: <%= javascript_include_tag "application" %>
7: <%= csrf_meta_tags %>
8: </head>
Rails.root: /home/tom/rails_projects/routesapp
Application Trace | Framework Trace | Full Trace
app/views/layouts/application.html.erb:5:in `_app_views_layouts_application_html_erb___1001173571477850876_70164200470120'
I generated the html files shown in the routes.rb file below; the html files are located in app/views/page
Routesapp::Application.routes.draw do
get 'page/home'
get 'page/about'
get 'page/contact'
Any ideas, comments, suggestions will be much appreciated. This is new to me. Thanks
Since you're a beginner, let me explain.
Your pages are showing; you've got an error:
undefined method `[]' for nil:NilClass
This is a standard Ruby error - it means undeclared variable.
Since Ruby is Object Orientated, it assigns "nil" values to the NilClass -- meaning that you end up with strange errors.
--
Normally, with debugging, you'll be able to reference the line number, and see what the issue is.
Because you've not included your view, I can only suggest that you try removing the following lines as a test:
5: <%= stylesheet_link_tag "application", :media => "all" %>
6: <%= javascript_include_tag "application" %>
If these work to resolve the issue, you'll have to either populate app/assets/javascripts/application.js or app/assets/stylesheets/application.css, or use something like nodeJS which works to resolve errors like this.
You'll also be better using the following for your routes:
#config/routes.rb
resources :pages, path: "page", only: [] do
%w(home about contact).each do |page|
get page
end
end
Buddy take "application" on line #5 and #6 and change that "application" word to "defaults"
As a bit of pre-text, I am used to Rails 2 but started building a sample app to get used to Rails 4 and I am having a nightmare with Sprockets and the asset pipeline even after reading the official guide and every question I can find on SO.
My css and js are included like so in my main view file:
<head>
...
<%= stylesheet_link_tag "application", media: "all" %>
<%= stylesheet_link_tag "style-responsive", media: "all" %>
<%= stylesheet_link_tag params[:controller], :media => "all" if stylesheet_exists?(params[:controller]) %>
<!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
<%= javascript_include_tag 'html5shiv' %>
<%= javascript_include_tag 'respond.min' %>
<![endif]-->
...
</head>
....
<%= javascript_include_tag "jquery-1.10.2.min" %>
<%= javascript_include_tag "jquery-ui-1.9.2.custom.min" %>
<%= javascript_include_tag "jquery-migrate-1.2.1.min" %>
<%= javascript_include_tag "bootstrap.min" %>
<%= javascript_include_tag "modernizr.min" %>
<%= javascript_include_tag params[:controller] if javascript_exists?(params[:controller]) %>
stylesheet_exists? and javascript_exists? are helper functions as I only want to include certain files when they are needed as opposed to the rest which are needed on every page.
The first error is:
Asset filtered out and will not be served: add `Rails.application.config.assets.precompile += %w( style-responsive.css )` to `config/initializers/assets.rb` and restart your server
If I then add that to assets.rb and restart, it moves on and the issue is repeated for every stylesheet_link_tag and javascript_include_tag in my view.
I could live with that even if it doesn't seem right but this comes crashing down when the interpreter gets to
<%= javascript_include_tag params[:controller] %>
Would I then need to also include every js file that I create for each controller? This seems wrong that I would have to constantly update the file whenever I create a new asset file.
In my application.css.erb I only have
*= require_self.
but I do have the old fashioned CSS #import for some stylesheets:
#import url(http://fonts.googleapis.com/css?family=Open+Sans:400,300,300italic,400italic,600,600italic,700,700italic,800,800italic);
#import url('bootstrap.min.css');
#import url('bootstrap-reset.css');
#import url('jquery-ui-1.10.3.css');
#import url('<%= asset_path 'css/font-awesome.min.css' %>');
#import url('custom-ico-fonts.css');
but all of these seem to work fine and don't need to be mentioned in assets.rb.
I have no requires set in application.js.
TLDR I think I am using Sprockets and the Asset Pipeline incorrectly, could someone please point out what it is I'm doing wrong and point me in the right direction?
I read about some similar issues to do with the sprocket-rails gem version 2.2.3 but I have 2.2.4 installed which is meant to have fixed any problems that existed in the previous version.
Rails 4.2.1
ruby 2.1.0p0 (2013-12-25 revision 44422) [x86_64-linux]
sprockets (3.0.1, 2.12.3)
sprockets-rails (2.2.4)
Sprockets wants to compact everything into a single file and minify it, so typically the pattern is to include all your javascript/stylesheets in the application manifests. There are plenty of good reasons for this pattern.
Since it appears you have removed the = require_tree . lines, this is not happening automatically and thus Rails wants to know about each individual file you plan to include separately via the assets.precompile configuration option. If requiring the entire directory is too aggressive, break your assets into subfolders and be more explicit about what you want to include.
Sprockets is relatively brittle and fighting against it is an uphill battle. So in both cases (JS/CSS), you should include it all and use selectors that are smart enough to scope page-specific styles or JS to that page.
That said, sometimes we cannot avoid having certain assets omitted from global inclusion. If you need to exclude a specific file from your manifest use a stub directive and include it separately with the HTML tag helpers.
Also note that you can have additional manifests (other files that include = require ... directives of their own) ... so long as you add those to the assets.precompile list.
The combination of stub and require directives and additional manifests should give you enough flexibility to organize your assets to your liking and make adding additional assets frictionless.
I'm at 5.1.2 of the railstutorial, I have just installed Bootstrap-sass (I've double checked, the gem is there). http://ruby.railstutorial.org/chapters/filling-in-the-layout#top
I added this file:
app/assets/stylesheets/custom.css.scss
And when I give it this content:
#import "bootstrap";
My http://localhost:3000/static_pages/home does not work anymore. It gives the following error:
ArgumentError in Static_pages#home
Showing c:/Sites/rails_projects/sample_app/app/views/layouts/application.html.erb where line #5 raised:
different prefix: "e:/" and "c:/Sites/rails_projects/sample_app/app/assets/stylesheets"
(in c:/Sites/rails_projects/sample_app/app/assets/stylesheets/custom.css.scss)
Extracted source (around line #5):
2: <html>
3: <head>
4: <title><%= full_title(yield(:title)) %></title>
5: <%= stylesheet_link_tag "application", :media => "all" %>
6: <%= javascript_include_tag "application" %>
7: <%= csrf_meta_tags %>
8: <!--[if lt IE 9]>
Rails.root: c:/Sites/rails_projects/sample_app
Application Trace | Framework Trace | Full Trace
app/views/layouts/application.html.erb:5:in `_app_views_layouts_application_html_erb___557356520_29974776'
Any help would be much appreciated, thanks!
Your gems is in E: while your app is in C:\
When trying to #import, Assets module will search several places including gem path. But it can't recognize the disk within the path. That's why your #import fails.
Suggestion: Put your app and gems in same disk.
Side note: Don't use Windows for Rails development at all.
I am facing a problem when i fetched the rails project from github.
When i cloned the repository and try to run the code from a remote system, i got the following errors.
["ok","(function() {\n\n\n\n}).call(this);\n"]
(in e:/github_projects/myfork/TestRepo/TestProj/app/assets/javascripts/users.js.coffee)
Extracted source (around line #6):
3: <head>
4: <title>TestProj</title>
5: <%= stylesheet_link_tag "application", :media => "all" %>
6: <%= javascript_include_tag "application" %>
7: <%= csrf_meta_tags %>
8: </head>
9: <body>
I am currently using rails 3.2.0 in windows environment.
I have created only a simple rails project with user scaffold in order to test it.
Its working fine while i worked with that in my local system before moving to github.
Thanks,
Mani
It's quite strange, I might recommend that you delete everything in the user.js.coffee and save it and try again. It looks that there's some wrong returns in there.