How to set a variable from a helper method for inclusion in a SASS SCSS stylesheet?
Rename your SASS file to foobar.css.scss.erb
. Then include the helper module you need that contains the helper method by placing this line at the top:
<% environment.context_class.instance_eval { include MyHelper } %>
Then you can use the helper method with erb
.foo {
color: <%= cool_color %>
}
Ruby on Rails - Using helpers inside css erb file gives undefined method
Helpers are not available by default to templated .css files. They are intended to help in view construction only. However, you can try the workaround mentioned here using an initializer:
Rails.application.assets.context_class.instance_eval do
include YourHelperModule
end
Alternatively, if you only need this for one or a few files, you can use the solution mentioned here, by adding this code to the top of the .css.erb file:
<% environment.context_class.instance_eval { include YourHelperModule } %>
Change background image url by time
try this way
<script type="text/javascript">
var currentTime = new Date().getHours();
if ( currentTime> 6 | currentTime<9) {
if(document.body) {
document.body.background = "sunrise.jpg";
}
}
else if (currentTime>=9 &¤tTime < 20) {
if(document.body) {
document.body.background = "daytime.jpg";
}
}
else if (currentTime>20 &¤tTime < 24) {
if(document.body) {
document.body.background = "sunset.jpg";
}
}
else {
if (document.body) {
document.body.background = "nighttime.jpg";
}
}
</script>
source : http://www.sitepoint.com/forums/showthread.php?744436-Changing-div-background-image-based-on-time
is this an improper use of MVC?
I did this exact same thing about a month ago. I wrote an amazing extention to Enumerable
to be able to split the collection into groups of N, and then realized ActiveSupport already provided exactly that (almost).
Take a look at in_groups(number, fill_with = nil)
it will split an array into number groups, perfect for the view :)
Sass: Browser vendor prefixes
Sounds like you want to use the Compass box-sizing mixin. Your SASS file would look like this:
@import "compass/css3/box-sizing";
* {
@include box-sizing(border-box);
}
And would compile to this:
* {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box; }
You can see the other CSS3 Compass mixins here. Note, though, that Compass doesn't include prefixes like -ms-box-sizing
, for instance, since IE8+ has implemented it without a prefix. If you really want those extra properties, this is how you'd do it:
@import "compass/css3/shared"
* {
@include experimental(box-sizing, border-box, -moz, -webkit, -o, -ms, not -khtml, official);
}
Problems referencing root in Capybara test
You should be calling
visit root_path
and you should be requiring rails_helper, rather than spec_helper. since rails_helper is where the url helpers get included - 'config.include Rails.application.routes.url_helpers'. To fix the error you get from doing that we'd need to see the contents of config/initializers/environment_variables.rb
Related Topics
Rvm Ruby with Tk Installation (Osx)
How to Use Private Submit to Hide from Profile
Controller Can Not Detect Ajax Requests
Cannot Start Rails Server, "No Such File to Load -- Bundler/Setup"
Result of 'Rake Routes' in Ruby Script
Getting Headers from a Ruby Net::Http Request Before Making the Request
How to Include Blank Field in Select_Tag
Ruby Puts Not Outputting in Real Time
Handling Iframe with Capybara Ruby
Cucumber Not Finding Step Definitions
Install Nokogiri 1.6.1 Under Ruby 2.0.0P353 (Rvm Based Installation) Fails (Osx Mavericks)
Your Ruby Version Is 2.1.0, But Your Gemfile Specified 2.0.0
Trying to Get Content Inside Cdata Tags in Xml File Using Nokogiri
How to Convert Boolean Values to Integers
Rails G Migration Doesn't Work
How to Render a PDF in the Browser That Is Retrieve via Rails Controller