Save_and_open_page not picking up scss markup - ruby-on-rails-3

Just upgraded a RoR 3.0 project to 3.2. I've moved the CSS assets to the asset pipeline and now using SASS. My Rspec request specs still pass, but when I throw in a save_and_open_page statement, the resulting page doesn't have any CSS stylings. The HTML rendering is all accurate, explaining the passing tests.
Any config ideas?

You can use capybara-screenshot gem for debugging.
It will take a screenshot of the page you want to debug.
Install the gem and use screen_shot_and_open_image instead of save_and_open_page

Related

Use Haml files in Redmine plugin

I am creating a Redmine plugin and would like to use Haml for the view templates. There is an existing plugin which has Haml views (ekanban) and it does not contain any special code to get Haml working other then having you add require 'haml' to your main application's Gemfile.
So here is what happens -- the templating system loads the .html.haml file correctly but renders the HAML markup (like it was rendering ERB).
I've tried to insert the require 'haml' at various intervals to no avail. I've even tried manually trying to activate Haml.init_rails(...) as suggested in this SO question. I've tried inserting that in a few places, tried it in a Rails.configuration.to_prepare block in the plugins' init.rb file. I've tried telling the Gemfile to not require 'haml' and attempting to do it during plugin load to no avail. What gives?
The view template had Textile in it and I did not notice because the markup for <h2> is similar (h2. vs. %h2). Including gem 'haml_rails' in the plugin's Gemfile is sufficient with no extra code.
Read carefully Installation instruction for this gem :)
Add "gem 'haml'" to your #{RAILS_ROOT}/Gemfile
I can't agree with this strategy: plugin can't change Redmine core! Any Redmine plugin can have own gems (defined in own Gemfile) - so I think you can create Gemfile in your plugin, run bundle install from the Redmine root and I believe you will manage to use Haml

Is there a "Rails Way" include a jQuery plugin in the Asset Pipeline?

Many jQuery plugins have the following directory structures:
/<plugin name>
../css
../images
../js
The CSS files usually have relative links to the images in them. What I want to do is include these plugins in the Rails Way under the Asset Pipeline, and hopefully that doesn't involve having to renamed the file references to remove the relative links. Is there such a Rails Way?
Could it also be that it's overkill to include an already-minified jQuery plugin in the Asset Pipeline?
You should try to add your assets to the load path which is the recommended way, as far as I know. If the application you're running has the assets-pipeline activated, it should find your assets after expanding the path in your application.rb
config.assets.paths << Rails.root.join("plugins/plugin_name/assets/")
Not shure, if this is what you asked for but if not, you should check: http://guides.rubyonrails.org/asset_pipeline.html#asset-organization
Remeber to restart your server
I had the same issue and also tried to find "the Rails way" to do this. And this is what I ended up with at the end of the day:
As Rob already mentioned:
vendor/assets is for assets that are owned by outside entities, such as code for JavaScript plugins and CSS frameworks.
Source: 2.1 Asset Organization
Lets take a practical example: using the jquery_datepicker gem (Note: we had to use a workaround because of this issue: bundle pack does not work with git sources).
1) Installing the gem (pretty straighforward):
cd vendor/gems
git clone https://github.com/albertopq/jquery_datepicker.git
2) Add this to your Gemfile
gem 'jquery_datepicker', :path => 'vendor/gems/jquery_datepicker'
3) Install a jquery-ui theme
From ThemeRoller select a theme, check Datepicker and Slider
and the jQUery version
Download and extract the content of the package
CSS/images from the css/theme-name folder move them:
jquery-ui-1.8.xx.custom.css to app/vendor/stylesheets/
the images folder to app/vendor/images/ (yes, move the entire folder images so you end up with something like this app/vendor/images/images/ui-icons_256x240.png
i18n from the development-bundle/ui/i18n folder (optional) move them to:
Create a folder i18n under app/vendor/javascripts/
move jquery.ui.datepicker-xx.js to this folder app/vendor/javascripts/i18n/
make sure the i18n folder is loaded so include in application.js
//= require_directory ./i18n
vendor/assets is loaded automatically AFAIK so you don't have to include the path in the asset pipeline.
I'd like to see how others are approaching this, it's a very good question.
I think the reason you haven't received an answer is because it's kind of unclear what you're asking. Are you asking if it's overkill to put your plugins in the asset pipeline? Are you asking if you have to rename file references?
I always put all my jquery plugins in my asset pipeline. Overkill or not, there all in one place and they only get compiled once so even if compiling them takes longer, it doesn't affect my app.

Ruby on Rails asset recompiling

With ruby on rails application, does assets needs to be totally recompiled? or is RoR smart enough to pick out the assets that did not change?
ie) If I changed 1 js file out of 100 js files, is there a way to recompile the 1 js file? OR do I have to wait for 100 js files to be compressed?
Rails doesn't differentiate between modified and unmodified assets as of yet. However, you can install turbo-sprockets-rails3 gem for this purpose.

Rails3 couldn't find file 'bootstrap'

This has hit me twice and I cannot get past it this time. The first time, I pushed/pulled from github and got webrick to boot up. This a.m. I attempted to do the same thing. I do recall restarting my dev machine yesterday which would cause webrick to restart.
Background, this is my first 'production' app and I'm using danielkehoe's starter template on github that uses cucumber, rails3 and devise. I've chosen Twitter-bootstrap as my CSS generator.
Hunting on the web suggested bundle update, rebooting webrick. Of those google results that directly mirror mine, there was no resolution posted. I have branched out and installed rails 3.2 but that made no difference.
Here is the Exception:
couldn't find file 'bootstrap'
(in /Users/sam/apps/keriakut/app/assets/stylesheets/application.css.scss:6)
Extracted source (around line #10):
9: <meta name="author" content="">
10: <%= stylesheet_link_tag "application", :media => "all" %>
11: <%= javascript_include_tag "application" %>
My trace:
app/views/layouts/application.html.erb:10:in
`_app_views_layouts_application_html_erb___2282066720260402873_2178181480'
I would have thought that caching is not used in development mode and doesn't that file look like it's cached?
It seems there is no bootstrap document for twitter-bootstrap, but it seems to be incorporated into sass, scss files? This is my inexperience showing.
Based on another stackoverflow answer I added: gem "twitter-bootstrap-rails", "~> 2.0rc0" into my Gemfile but after updating, the results are not the same. I want to understand what I'm doing wrong with my environment to keep this coming up, sam
I think you're including too many unrelated details. Sounds like you have /*= require twitter/bootstrap or similar in your application.css.scss manifest and it can't be found. Bootstrap doesn't come with Rails or Sass. You can either drop it manually into your stylesheets directory from the Bootstrap website and require it or you can use one of the gems out there that contains it.
Since you're using the twitter-bootstrap-rails gem, the documentation says that you install it by running:
rails generate bootstrap:install
That will probably unpack the bootstrap css files from the gem into your stylesheets directory.
And your application.css.scss should contain:
*= require twitter/bootstrap

Rails 3.1 precompiled assets breaking javascript remote_forms in production mode

I've fixed all the errors about "xxx" is not compiled and all the assets show up -- when running locally everything works fine:
All ajax requests work
Form submissions use the rails remote tag and fire off properly
However when running in production mode locally (and on Heroku):
Some ajax will work -- however things like PUT's that should be updatating records (and do in dev) don't... They will hit the page but not do the actual database update
Remote forms are completely broken and resulting in regular form submission
The source can be cloned from here: https://github.com/bluescripts/reru_scrum
Maybe I'm miscompiling the assets wrong or maybe I'm missing an appropriate include in my application.js file?
I've been compiling via:
rake assets:precompile
You're missing //= require jquery_ujs in your application.js. This file comes with jquery-rails gem and is responsible besides other things for handling remote links and forms.
Btw, I'd suggest removing .Gemfile.swp from your repo and adding .*.swp to .gitignore.