Issue loading rails 3 (server) after coming back from 3.1 - css

total noob to rails and am using the Hartl tutorial.
Got to chapter 4 (CSS, 4.1.2), everything seemed dandy, and ran into an issue getting
<!DOCTYPE html>
<html>
<head>
<title><%= title %></title>
<%= csrf_meta_tag %>
<%= stylesheet_link_tag 'blueprint/screen', :media => 'screen' %>
<%= stylesheet_link_tag 'blueprint/print', :media => 'print' %>
</head>
<body>
<%= yield %>
</body>
</html>
to make the text on the page look 'prettier'. As Hartl describes it,
'By the way, with the new stylesheets the site doesn’t look much different than before, but it’s a start'
I do agree it looks cooler and this step is obviously more than necessary to continue.
So, nothing was changing on the localhost:3000/pages/home as it looked in chapter 3.
This is what it SHOULD look like
http://ruby.railstutorial.org/images/figures/home_with_stylesheet.png
(see attached pic^)
So I finally moved the stylesheets folder from public into app/assets/stylesheets, and added
this
<%= stylesheet_link_tag 'application.css' %>
to the application.html.erb file in app/views/layouts folder
Which I found from this portion of stackoverflow :) very helpful
So I fired up localhost:3000/pages/home and everything looked as it should (in relation to the png pic posted above) but all the text was centered, and it should be on the left side.
And, in addition, I was getting this message, repeated, in the terminal:
Started GET "/assets/stylesheets/src/typography.css?body=1" for 127.0.0.1 at 2012-01-04 17:34:13 -0800
Served asset /stylesheets/src/typography.css - 304 Not Modified (3ms)
[2012-01-04 17:34:13] WARN Could not determine content-length of response body. Set content- length of the response or set Response#chunked = true
So a buddy said it had to do with the rails version. We did share screen skype and he said in the home directory it should be 3.1 and in the sample_app directory it should be version 3.0.11 (he's a bit of a noob too but everything is going smoothly for him)
So alas I am back to getting the damn rails server to work. I'm on Snow Leopard and changed the sqlite3 thing, did bundle update then bundle install and worked fine. Now 'rails s' will not work ;/
the error message in the terminal is this:
/Users/davidpardy/rails_projects/sample_app/config/application.rb:8:in `require': no such file to load -- sprockets/railtie (LoadError)
from /Users/davidpardy/rails_projects/sample_app/config/application.rb:8:in '<top (required)>'
from /Users/davidpardy/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.11/lib/rails /commands.rb:28:in `require'
from /Users/davidpardy/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.11/lib/rails/commands.rb:28:in `block in <top (required)>'
from /Users/davidpardy/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.11/lib/rails/commands.rb:27:in `tap'
from /Users/davidpardy/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.11/lib/rails/commands.rb:27:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
So now I'm stuck and really don't know what to do. Don't want to start from scratch.
Like I said I'm new to this so any input would be appreciated. This seems like a rather easy fix, just lost.

im in the same boat as you, i am running rails 3.1.3 and am not in the mood atm to start over for a lower rails (or to figure out how to seamlessly change rails version).
i decided to remove the blueprint folder and its two including lines in application.html.erb, and make a new inclusion of a custom css file i put directly in app/assets/stylesheets. the css was just to make the background red, and thats what it did. not sure why our pages were being centered like that using the blueprint, but it looks okay now. as mentioned earlier, the safest bet is to just use the same versions as the tutorials, or 3.0.11 for rails as mr. hartl has indicated in a comment.

Per the answer to Trouble loading Rails Server (3.0.11, ruby 1.9.2), no such file to load -- sprockets/railtie (LoadError), you should remote Rails 3.1-specific lines from auto-generated files, mostly in config/.
One way to figure out what lines to remove is to compare your app to a fresh Rails 3.0 app using diff -r
Step 1: Create a clean Rails 3.0 app
$ rails --version
Rails 3.0.10
$ rails new fresh_app
create
create README
create Rakefile
Step 2: Use diff -r to compare the directories
$ diff -r hartl_tutorial/config fresh_app/config
diff -r hartl_tutorial/config/application.rb fresh_app/config/application.rb
5,10c5,7
< if defined?(Bundler)
< # If you precompile assets before deploying to production, use this line
< Bundler.require(*Rails.groups(:assets => %w(development test)))
< # If you want your assets lazily compiled in production, use this line
< # Bundler.require(:default, :assets, Rails.env)
< end
---
> # If you have a Gemfile, require the gems listed there, including any gems
> # you've limited to :test, :development, or :production.
> Bundler.require(:default, Rails.env) if defined?(Bundler)
In case you don't know how to read a diff, the basic idea is that lines starting with < are from one file while lines starting with > are from the other file.

Related

Customizing Powerleve10k prompt

I just added the Powerlevel10k theme to my zsh and i'm trying to configure certain parts.
It currently looks like this:
The ~/.p10k.zsh has a lot of configurations done and I've been trying to change certain things but i'm not there yet.
I don't want to print the whole path on the left prompt, just the directory. Also, not sure what those numbers indicate in the git section. And the right prompt is displaying my ruby version, although I haven't used Ruby in ages and want to change it to a different setting.
I've tried adding a PS1=... to .zshrc but it seems to be overriden by the P10K config file.
Any suggestions?
Display only the last directory segment
Open ~/.p10k.zsh.
Search for POWERLEVEL9K_SHORTEN_STRATEGY.
Change the value of this parameter to truncate_to_last.
Alternatively, change the value of POWERLEVEL9K_DIR_MAX_LENGTH to 1. This will maximally shorten current directory while keeping the transformation reversible. You can restore the original directory by copy-pasting the shortened directory to the command line and pressing TAB.
Ruby version
Powerlevel10k has several prompt segments that can display Ruby version. By default only those are enabled that display Ruby version when it has been manually overridden by some tool (e.g., rbenv or asdf).
To remove Ruby version from prompt:
Open ~/.p10k.zsh.
Search for POWERLEVEL9K_RIGHT_PROMPT_SEGMENTS.
Remove or comment out the following elements: rbenv, rvm and asdf.
Alternatively (and perhaps preferably), find out which tool is overriding Ruby version for you and remove the override if you no longer need it.
shorten dir segment to show only deepest directory
To show only last n significant path segments, you can set following in your config .zshrc, e.g n=1 means show only last folder in present working directory:
POWERLEVEL9K_SHORTEN_DIR_LENGTH=1
See https://stackoverflow.com/a/49027654
explain Git symbols
The question/exclamation mark in Git segment (vcs segment, next to path) means the number of files untracked (?) and unstaged (!). For detailed description see What do different symbols in Git status mean?
change version segment
You can change the version segment (on the right of prompt) to reflect another tool. For example to replace shown ruby version by python version replace the element within right promt elements in your config .zshrc:
POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(rbenv)
by
POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(pyenv)

GNAT Metric and RTL files

For running GNAT metric (for Windows, GPL 2017 or CE 2018) I'd like to include the RTL sources as well. There is a "-a" switch but it seems to be ineffective. When I'm forcing visibility of RTL sources, only ada.ads and system.ads are processed. Guessing it is a "crunched name" issue (RTL file names forced to 8 character names) I've tried other tricks without success.
My question is: is there a way to get the RTL source metrics (of the source files actually used) with GNAT Metric?
I'm using the command
gnatmetric -a -xs -nt -j0 -Pmyproj.gpr -U somemain.adb
TIA
In the meantime I've found a workaround by using the gnathtml.pl script.
I've customized the script a bit by removing the H1 headers.
The result is a few hundreds of HTML files with the sources of units actually used: the script does find all dependencies, recursively, through the .ali files - including the RTL.
Then I group the HTML files together, convert them back to text files, pass them through Adalog's Normalize tool for removing comments and empty lines, count lines with the wc command, and the job is done.

Why does uglify-js report 'WARN: Output exceeds 32000 characters'?

build pipeline is: Typescript, browserify, browserify-css, uglify.
runtime libraries: react, bootstrap.
My application so far has very little functionality (that's why I'm asking if this is going to bite me later, even though it appears to work for now). Later on it will get bigger (react-router, redux, other js libraries like Auth0, maybe even some actual functionality.)
I have an app.css that contains:
#import url("node_modules/bootstrap/dist/css/bootstrap.css");
I then import that into my index.tsx with:
import './app.css';
This all appears to work in that my helloworld react component displays "hello world".
But, during the build, uglify reports:
WARN: Output exceeds 32000 characters
Should I ignore it? And if so, is there a way to suppress it?
Looking at the file produced by uglify shows that it seems to make sure no lines are > 32000 characters - most lines truncate at just short of 32000 (one at 31999).
But there's one line var css='/*!\n * Bootstrap v3.3.7 ...' that is 120K characters long. I assume this is what Uglify is trying to tell me, but what's the big deal?
As per DavidG's comment, you can tell Uglify not to complain about this with the max-line-len option.
But, you can't just add that option, because it only works if you're "beautifying" the code. Which then does other stuff that you may not want to do.
The solution to that is to use the -b option to enable beautification, but then tell Uglify not to actually beautify. o_O
"scripts": {
"uglifyjs":"uglifyjs -b beautify=false,max-line-len=120000"
}
The above will set the line length to 120K - which made the warning go away.
This is more of a workaround than an answer though - it answers the "how do I suppress it" part of my question. I still don't know why it's warning me about that - problems with older browsers or whatever, I don't know.

SCSS precompile:assets throws invalid CSS due to http url in compiled asset file

Rails 3.1.22
sass-rails 3.2 - actionpack dependency prevents upgrading
rake assets:precompile throws error in a file called admin.css.scss
Here is the compile portion where it's complaining :
td .current{padding-right:12px;background-repeat:no-repeat;background-position:right center}
td .asc{background-image:url(http://cdn3.mysite.com/assets/up_arrow-b4361e6bd6a8af6d7d60f73acca6d973.gif)}
td .desc{background-image:url(http://cdn2.mysite.com/assets/down_arrow-d4345de2e0e231338210ca20e63f302a.gif)}
#overlay{background:url(http://cdn0.mysite.com/assets/loading-c9c18d94ad7c119962ed93ca742e78b6.gif)
I have these files in production right now, but the last time I precompiled was probably 6+ months ago - at that time I still had the CDN in effect and can't figure out what's different.
I've tried variations before coming to SO - image-url, image-path, asset-url, asset-path, tried changing scss to css.erb and using the <%= asset_path () %> helper, I keep getting this error. The actual error is :
Sass::SyntaxError: Invalid CSS after " http": expected ";", was "://cdn2.mysite..."
Does anyone have any idea how I can resolve this syntax error?
The url needs to be included in a single quote '' or double quotes ""
from: https://developer.mozilla.org/en-US/docs/Web/CSS/url
The url() functional notation The URI may be quoted by single or
double quotes. Relative URIs are allowed and are relative to the URL
of stylesheet (and not to the URL of the web page).

Async Rails 3.1 problem with assets

I have a problem with assets on an asynchronous rails 3.1 application, I managed to build a minimal example showing my problem but it did not helped me much.
The application is really simple, what I did was:
- create a fresh application with 3.1 (non rc)
- add thin+Rack::FiberPool
- setup bourbon (scss mixins)
- run the application
Now I start a server with "rails server thin", after that any request will end up in a "stack level too deep" with only one backtrace line :/
Here is the minimal application: https://github.com/schmurfy/assets_crash
Here is the backtrace I get when doing a request:
http://dl.dropbox.com/u/1313066/github/crash_assets.png
I tried to dig in to see where the problem was which led me in sass-rails in the file template_handlers.rb:
def sass_options(scope)
importer = self.importer(scope)
options = sass_options_from_rails(scope)
load_paths = (options[:load_paths] || []).dup
load_paths.unshift(importer)
# bnding.pry
options.merge(
:filename => eval_file,
:line => line,
:syntax => syntax,
:importer => importer,
:load_paths => load_paths,
:custom => {
:resolver => Resolver.new(scope)
}
)
end
I tried to explore with Pry (an irb alternative) and what I found is even more puzzling: While at the binding.pry line I can trigger a stack level too deep with:
{}.merge(:anything => Resolver.new(scope))
The result is immediate but I cannot find anything in that object which would explain the result.
Any lead would be welcome.
I finally found the answer: fibers only have 4Kb of stack space and Ruby on Rails is now too big to fit in this space :/
I had the same problem, upgraded my ruby to 1.9.3-preview1 and built all my gems from the ground up now everything works.
EDIT:
OK after playing with it a little more it really seems as if Rack::Fiberpool causes this issue. Got it back after I inserted Rack::Fiberpool back in my Rails stack...
Disable assets pipline in rails. Don't require sass-rails but instead require sass and sprockets in Gemfile. Here is my config.ru to serve assets:
require ::File.expand_path('../config/environment', __FILE__)
Sass::Engine::DEFAULT_OPTIONS[:load_paths].tap do |load_paths|
load_paths << "app/assets/stylesheets"
load_paths << Compass::Frameworks['compass'].stylesheets_directory
load_paths << Compass::Frameworks['twitter_bootstrap'].stylesheets_directory
end
builder = Rack::Builder.new do
map '/assets' do
environment = Sprockets::Environment.new
environment.append_path 'app/assets/javascripts'
environment.append_path 'app/assets/stylesheets'
run environment
end
map '/' do
use Rack::FiberPool, :size => 250
run YourApp::Application
end
end
run builder
It needs to precompile assets in production. I will look on it later.

Resources