I'm running Rails3 with twitter-bootstrap-rails. I have 2 different layouts "application.html.erb" and "backend.html.erb". Unfortunately, when using the backend layout I still get all the bootstrap_and_overrides.css.less styles overriding the defaults. I would like to only use a separate overrides file so the layout is different than my application layout.
Any suggestion on how best to do this?
The only way I can think to do this is to not require the override file in my application.css file (as suggested in the bootstrap readme) and instead require it in a CSS file that I only load in the application.html.erb file.
I didn't see that the application layout actually specified the application.css file. I modified that line to read:
<%= stylesheet_link_tag "backend", :media => "all" %>
And then created a backend.css file that did not reference the entire tree nor the original overrides file.
Now I have a generic layout that can be customized through the backend.css or my new bootstrap_and_overrides_backend.css.less file.
Im curious how you guys visual make distinction between the different Rails modes development/test and production?
Im afraid that since visually the apps look the same in each mode, my customer can use the wrong environment and enter production data in a test environment.
Now i change the background in my application CSS, to make sure there is a difference. BUt i rather would have something smart that automatically works based on the environment thats running. Maybe a BIG watermark?
Any best practices here?
Based on Artimuz answer i did the following:
Add this to the application_helper.rb
def development?
#is_development ||= (ENV['RAILS_ENV'] != 'production')
end
then in application.html.erb i added:
<head>
<% if development? %>
<style type="text/css">
html {
background-image: url(/assets/test.png);
background-color: silver;
}
</style>>
<% end %>
</head>
The test.png is just a transparent png with the word 'test' inside and a diagonal line. Works like a charm (its tiled), for sure you you can't miss your inside the development/test environment.
From here: http://markmail.org/message/grmor6rppm5jwgnh
You can test RAILS_ENV environment variable.
In application_helper.rb, add this method :
def production?
#is_production ||=(ENV['RAILS_ENV']=='production')
end
An d in your views/layouts:
<% if production? %>
...
<% end %>
I'm learning Rails as I go, and have been put on a project to update an existing site from Rails 2 to Rails 3.1.1. The app uses tinymce to allow an admin to edit several parts of the site's content. In our upgraded project, when I click this edit link the result is
Routing Error
ActionController::RoutingError (uninitialized constant Admin::ContentController::AppConfig):
app/controllers/admin/content_controller.rb:4:in `<class:ContentController>'
app/controllers/admin/content_controller.rb:1:in `<top (required)>'
I have searched all over the internet for help but this is unfortunately a somewhat generic name for a variable I guess? The project is using the gem, tinymce-rails, which I -think- is the correct option for rails 3.1. All I am trying to find out here is what is the root problem, so I know what part of the application needs to be updated so at least the page will load, even if there are more issues I need to fix afterwards...
I verified all of the steps from https://github.com/sandipransing/rails_tiny_mce#readme seem to be implemented (though that says rails 3.0, so I also looked over https://github.com/spohlenz/tinymce-rails)... Here's the code in the content controller that throws the error:
class Admin::ContentController < ApplicationController
before_filter :require_admin_login
uses_tiny_mce(:options => AppConfig.freysmile_options, :only => [:referral_center, :great_review_tips, :faq, :badge_assignment_mail, :point_assignment_mail, :add_referral_mail, :patient_invitation_mail])
The project seems to have tinymce-rails in the gemfile and also the plugins folder - it also has all of the plugins that are listed as being required on the first github link.
(Side note: Unfortunately this is a site made by someone else, given to our consulting boss who is not working with the original creator, and now my fiancee and myself are learning by updating this, so it is built in ways I would probably not have gone, but we do not have time for a complete redo.) Thanks for reading my question!
The uses_tiny_mce method is from another gem that is not compatible with rails > 3.1. You want to remove that method from any of your controllers and follow the instructions on the tinymce-rails readme. The tinymce-rails gem simply adds the tinymce javascript to your asset pipeline in rails-3.1+.
I don't know where the AppConfig.freysmile_options comes from. Search your app for 'freysmile'.
Here's how I'm using tinymce-rails with a 3.1.3 app:
Gemfile:
gem 'tinymce-rails'
application.js
//= require tinymce-jquery
views/shared/_mce.html.erb
<div id="form_content">
<h3><%= f.label :content %></h3>
<%= f.text_area :content, :cols => '100', :rows => '50', :class => 'mce' %>
</div>
<script type="text/javascript">
$(function() {
$('.mce').tinymce({
width: 1000,
theme: 'advanced',
theme_advanced_toolbar_location: 'top',
theme_advanced_buttons1: 'bold, italic, underline, strikethrough, justifyleft, justifycenter, justifyright, justifyfull, bullist, numlist, outdent, indent, cut, copy, paste, undo, redo, link, unlink, image, cleanup, code, removeformat, help',
theme_advanced_buttons2: 'formatselect, fontselect, fontsizeselect, styleselect, hr, sub, sup, forecolor, backcolor, forecolorpicker, backcolorpicker, charmap, visualaid, anchor blockquote',
theme_advanced_buttons3: ''
});
});
</script>
forms:
<%= render :partial => 'shared/mce', :locals => {:f => f} %>
I'm only using tinymce on columns named "content". If your columns have differing names, you'll have to adjust your partial locals to suit.
Maybe there's a better way to customize the buttons and layout without modifying the gem, but this is working well enough for me.
I'm working on a Rails 3.1 app using JavascriptMVC and ejs templates within the client to do some complicated features on my application. Unfortunately ejs syntax is very similar to erb syntax, to the point where I can't keep the code in the same file (although if someone knows of a good way to do this, I'd be ecstatic). Ultimately I want to be able to apply some rails code within the ejs template (say for I18n) but at this point I will just settle for getting this to work
Following the example from this question I have created a custom template handler that looks like this:
module CommonModel
class Handler < ActionView::Template::Handler
include ActionView::Template::Handlers::Compilable
def compile(template)
template.source.inspect
end
end
end
ActionView::Template.register_template_handler :ejs, CommonModel::Handler
Then I created a partial template that has my ejs code in it:
_jmvc_templates.html.ejs
<script type="text/ejs" id="my_ejs_template">
<div>Some ejs here</div>
</script>
Within my existing template, I attempt to include my partial:
<%= render 'path/to/my/ejs/templates/jmvc_templates' %>
At this point, the file is included and my handler is used, but everything is escaped, so my div in my template gets rendered to the page like this:
<div%gt;
I'm sure I'm missing something obvious here, but I don't know what it could be... How can I get this template handler to just include my ejs based template without escaping all of the html in it?
Edit:
I've found that calling render with html_safe works:
<%= render('path/to/my/ejs/templates/jmvc_templates').html_safe %>
This seems like a kludge though - there has to be a way to get the erb renderer to treat text from my handler as html safe text.
Maybee you should be using raw. Check this
def compile(template)
raw template.source.inspect
end
I am using the no configuration option and have taken the following steps:
put the js files into root/public/javascripts
put the image files into root/public/images
put the demo css files into root/public/stylesheets
put css call in the head section of my layout file
<%= stylesheet_link_tag "demo_table", :media => "all" %>
put the initialization script in the head section of my layout file:
<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
$('#example').dataTable();
} );
</script >
first line of my table layout is:
<table width="100%" style="border-collapse:collapse; " id="example">
I restarted my server. Nothing happens. What am i missing?
The zero config relies on having a properly formatted table, which your example isn't showing. It must also have <thead> and <tbody> elements to render properly. Ensure that's properly setup first.
Second, open the page in Chrome or Firefox, view source. Click on the links to the Datatables.js and Datatables.css files as well as Jquery.js (or whatever each of these files is named) Do they open? If not, there's your problem.
Javascript is essentially platform independent. Sure, you get information TO the script in different manners in Rails, PHP, .net, etc, but there's no reason that this doesn't work in any of the major scripting language.
I have been using the RailsDatatables plugin in my rails apps without any problem. Maybe give that a try?