Ruby On Rails Syntax error in Welcome#Index - html

I was implementing bootstrap into my ruby on rails app and now I've got the following error:
Sass::SyntaxError in Welcome#index
Showing /home/ubuntu/workspace/app/views/layouts/application.html.erb where line #6 raised:
File to import not found or unreadable: bootstrap-sockets.
Load paths:
/home/ubuntu/workspace/app/assets/images
/home/ubuntu/workspace/app/assets/javascripts
/home/ubuntu/workspace/app/assets/stylesheets
/home/ubuntu/workspace/vendor/assets/javascripts
/home/ubuntu/workspace/vendor/assets/stylesheets
/usr/local/rvm/gems/ruby-2.1.5#rails4/gems/turbolinks-2.5.3/lib/assets/javascripts
/usr/local/rvm/gems/ruby-2.1.5#rails4/gems/jquery-rails-3.1.2/vendor/assets/javascripts
/usr/local/rvm/gems/ruby-2.1.5#rails4/gems/coffee-rails-4.0.1/lib/assets/javascripts
/usr/local/rvm/gems/ruby-2.1.5#rails4/gems/bootstrap-sass-3.3.4.1/assets/stylesheets
/usr/local/rvm/gems/ruby-2.1.5#rails4/gems/bootstrap-sass-3.3.4.1/assets/javascripts
/usr/local/rvm/gems/ruby-2.1.5#rails4/gems/bootstrap-sass-3.3.4.1/assets/fonts
/usr/local/rvm/gems/ruby-2.1.5#rails4/gems/bootstrap-sass-3.3.4.1/assets/images
/usr/local/rvm/gems/ruby-2.1.5#rails4/gems/bootstrap-sass-3.3.4.1/assets/stylesheets
(in /home/ubuntu/workspace/app/assets/stylesheets/application.css.scss:17)
Extracted source (around line #6):
3
4
5
6
7
8
9
<head>
<title>Bloccit</title>
<meta name="viewport" content="width=device-width, initial-scale=1"
<%= stylesheet_link_tag "application", media: "all" %>
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
<%= csrf_meta_tags %>
</head>
Rails.root: /home/ubuntu/workspace
Application Trace | Framework Trace | Full Trace
app/assets/stylesheets/application.css.scss:17
app/views/layouts/application.html.erb:6:in `_app_views_layouts_application_html_erb___973947755503535086_42092360'
Request
Parameters:
None
Toggle session dump
Toggle env dump
Response
Headers:
None
What could be causing it?

It shows that error is in your
app/assets/stylesheets/application.css.scss:17
Please check that properly and let me know.

Related

Application.html.erb in rails 4

I am new to rails 4.0.2 .
I am working on a application with rails version 4 and ruby 2. In views the application.html.erb file is not working. It is not replicating on all the view files.
This is my code in application.html.erb file:
<!DOCTYPE html>
<html>
<head>
<title>Myapp</title>
<%= stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true %>
<%= javascript_include_tag "application", "data-turbolinks-track" => true %>
<%= csrf_meta_tags %>
</head>
<body>
<%= yield %>
</body>
</html>
I have a controller named xyz_controller.rb which has the following code:
class xyzController << ApplicationController
end
The application_controller.erb file has the following code:
class ApplicationController < ApplicationController
def login
end
end
The login.erb file contains the normal html code.
Thanks in advance.
Your application controller should look like this:
class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception
end
Your XYZ controller should look like this:
class XyzController < ApplicationController
def action
#here you define instance variables used in your view for this action
end
...
end
... so your login action, for instance, would be defined there.
Your view should be named action.html.erb, where action matches your controller action and that file should be in app/views/xyz.
The Rails mantra is convention over configuration. This means that everything will be a lot easier if you (very closely) follow the Rails conventions for naming, etc. I strongly recommend working your way through a good tutorial like Hartl's if you haven't already.
Hope this helps.

Why does my title tag not appear on search results using Ruby on Rails?

I'm trying to add a title tag to my website using ROR.
After adding the desired changes to ... in aplication.html.erb, then commiting and deploying it, I still do not see the complete title tag present with the changes I just made when I view the website on search results.
Why is this the case and is there anything I am forgetting to include?
<!DOCTYPE html>
<html>
<head>
<title>Website Name - Desired title tag added here but doesn't show in search results</title>
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
<%= csrf_meta_tags %>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<%= render 'shared/user_info' %>
</head>
<body>
<div id="body-interior">
<%= render 'shared/header' %>
<div class="container">
<% flash.each do |name, msg| %>
<%= content_tag(:div, msg, class: "alert alert-info") %>
<% end %>
<%= yield %>
</div>
<%= render 'shared/footer' %>
</div>
<%= render 'shared/final_scripts' %>
</body>
</html>
Thanks!
When you say search results, I assume you mean search engines like Google? If so, you need to know that changes like these won't be recognized instantly by Google. The changes should be visible as soon as Google (or any other robot) crawls the page in question again.
As far as I know you can force this process with Google's Webmaster Tools.

Errno::EACCES in Welcome#index

I'm getting this error after creating a test app on Rails 4.1.5 , currently running on a test enviroment configured with apache and mysql, using passenger, on Fedora 21 so far I´ve tried everything regarding ownership and permissions, but it is still not working.
Permission denied # dir_s_mkdir - /var/www/html/blog/tmp
(in /var/www/html/blog/app/assets/stylesheets/welcome.css.scss)
Extracted source (around line #5):
<html>
<head>
<title>Blog</title>
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-
track' => true %>
<%= javascript_include_tag 'application', 'data-turbolinks-track' =>
true %>
<%= csrf_meta_tags %>
</head>
Rails.root: /var/www/html/blog

Show a different style sheet depending on page in rails 4

I am trying to render different CSS depending on the page. I did some research
How does one load a CSS framework in Rails 3.1?
https://github.com/rails/rails/issues/1981
and of course the rails guide on the asset pipeline.
What I want is for the index(home page) to render one css file(welcome.css.scss) and the others to render users.css.scss.
Right now when you navigate to the page it renders the welcome.css.scss and then when I hit sign in it is still rendering welcome.css.scss. But after refreshing the page it will then render the user.css.scss
I updated my assets.rb file:
Rails.application.config.assets.precompile += %w( welcome.css )
Rails.application.config.assets.precompile += %w( users.css )
Then I created a welcome.html.erb
<!DOCTYPE html>
<html>
<head>
<title>Blocmarks</title>
<%= stylesheet_link_tag "welcome" %>
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
<%= csrf_meta_tags %>
</head>
<body>
<%= yield %>
</body>
</html>
and a users.html.erb file
<!DOCTYPE html>
<html>
<head>
<title>Blocmarks</title>
<%= stylesheet_link_tag 'users' %>
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
<%= csrf_meta_tags %>
</head>
<body>
<%= yield %>
</body>
</html>
I removed the require from the application.css.scss. The only thing in the file at this time is #import 'bootstrap';
and of course I have a welcome and a user.css.scss.
Results from the console:
-Navigate to the home page
Started GET "/" for 127.0.0.1 at 2014-10-25 13:04:11 -0500
ActiveRecord::SchemaMigration Load (0.3ms) SELECT "schema_migrations".* FROM "schema_migrations"
Processing by WelcomeController#index as HTML
Rendered welcome/index.html.erb within layouts/welcome (13.0ms)
Completed 200 OK in 471ms (Views: 446.7ms | ActiveRecord: 0.0ms)
Navigate to the users/sign-in
Started GET "/users/sign_up" for 127.0.0.1 at 2014-10-25 13:04:57 -0500
Processing by Devise::RegistrationsController#new as HTML
Rendered devise/shared/_links.erb (2.7ms)
Rendered devise/registrations/new.html.erb within layouts/devise (615.4ms)
Completed 200 OK in 896ms (Views: 890.9ms | ActiveRecord: 0.9ms)
Refresh the users/sign page:
Started GET "/users/sign_up" for 127.0.0.1 at 2014-10-25 13:06:02 -0500
Processing by Devise::RegistrationsController#new as HTML
Rendered devise/shared/_links.erb (0.8ms)
Rendered devise/registrations/new.html.erb within layouts/devise (7.4ms)
Completed 200 OK in 308ms (Views: 306.3ms | ActiveRecord: 0.0ms)
I also created a gist with the full console results to show what it is GETting first:
https://gist.github.com/tjperry07/b3093c0b7f16b5e000b0
This is happening because of rails turbolinks. It makes following links in your web application faster. Instead of letting the browser recompile the JavaScript and CSS between each page change, it keeps the current page instance alive and replaces only the body and the title in the head.
If you look at guides or turbolinks docs. It's clearly stated that
If using the turbolinks gem, which is included by default in Rails 4, then include the 'data-turbolinks-track' option which causes turbolinks to check if an asset has been updated and if so loads it into the page
FIX:
Replace your stylesheet tags with these:
<%= stylesheet_link_tag "welcome", media: "all", "data-turbolinks-track" => true %>
<%= stylesheet_link_tag "users", media: "all", "data-turbolinks-track" => true %>

Bootstrap doesn't seem to be importing

I'm very new to RoR and have been following along with Michael Hartl's tutorial and have now been stuck on the part that introduces the Bootstrap framework. All gems are being updated and installed.
locales/application.rb
require File.expand_path('../boot', __FILE__)
# Pick the frameworks you want:
require "active_record/railtie"
require "action_controller/railtie"
require "action_mailer/railtie"
require "sprockets/railtie"
# require "rails/test_unit/railtie"
# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(:default, Rails.env)
module SampleApp
class Application < Rails::Application
# Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers
# -- all .rb files in that directory are automatically loaded.
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
# config.time_zone = 'Central Time (US & Canada)'
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
# config.i18n.default_locale = :de
config.assets.precompile += %w(*.png *.jpg *.jpeg *.gif)
end
end
application.html.erb
<!DOCTYPE html>
<html>
<head>
<title><%= full_title(yield(:title)) %></title>
<%= stylesheet_link_tag "default", media: "all", "data-turbolinks-track" => true %>
<%= javascript_include_tag "default", "data-turbolinks-track" => true %>
<%= csrf_meta_tags %>
<%= render 'layouts/shim' %>
</head>
<body>
<%= render 'layouts/header' %>
<div class="container">
<%= yield %>
<%= render 'layouts/footer' %>
</div>
</body>
</html>
home.html.erb
<% provide(:title, 'Home') %>
<div class="center hero-unit">
<h1>Welcome to the Sample App</h1>
<h2>
This is the home page for the
Ruby on Rails Tutorial
sample application.
</h2>
<%= link_to "Sign up now!", '#', class: "bttn btn-large btn-primary" %>
</div>
<%= link_to image_tag("rails.png", alt: "Rails"), 'http://rubyonrails.org/' %>
custom.css.scss
#import "bootstrap";
/* universal */
html {
overflow-y: scroll;
}
border-style: {
padding-top: 60px;
}
section {
overflow:auto;
}
textarea {
resize: vertical;
}
.center {
text-align: center;
}
.center h1 {
margin-bottom: 10px;
}
Something that I've gathered is most likely incorrect is the fact that the source code of /home.html.erb does not make any references to /styles/bootscrap.css . Should I have a bootstrap.css file along with my other stylesheets? If so it's not mentioned in the tut.
<head>
<title>Ruby on Rails Tutorial Sample App | Home</title>
<link data-turbolinks-track="true" href="/stylesheets/default.css" media="all" rel="stylesheet" />
<script data-turbolinks-track="true" src="/javascripts/default.js"></script>
<meta content="authenticity_token" name="csrf-param" />
<meta content="n2QVul+/didf2xA6jj3QelpDZdOrUpgaWcDp1XFQACM=" name="csrf-token" />
<!--[if lt IE 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<! [endif]
This is what /static_pages/home looks like for me :
my home
vs. the one from the tutorial : tutorial home
I can't think of anything else to include but if I've missed something I'll be sure to follow up quickly. Thanks!
In application.html.erb,
it should be "application", not "default".
<%= stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true %>
<%= javascript_include_tag "application", "data-turbolinks-track" => true %>
https://github.com/railstutorial/sample_app_rails_4/blob/master/app/views/layouts/application.html.erb