tinymce uninitialized constant AppConfig in rails 3.1? - ruby-on-rails-3

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.

Related

testing gmap4rails without selenium

We're just playing around with the infowindows in our project that uses gmap4rails. Pulled stuff out into a partial as recommended:
#json = #results.to_gmaps4rails do |org, marker|
marker.infowindow render_to_string(:partial => "popup", :locals => { :#org => org})
end
Partial has this:
and we've checked that we can match xpath with it in chrome like so:
$x("//div[#class='map_container']//a[#href='/organizations/127']")
however this doesn't work in a cucumber spec like so:
expect(page).to have_xpath("//div[#class='map_container']//a[#href='#{organization_path(org)}']")
All code in a branch here: https://github.com/tansaku/LocalSupport/tree/map_links
Is there a recommended best practice for integration tests of the infowindows? I can write a view spec for the partial, or a controller spec etc., but perhaps there's no way to integration test the infowindow contents since that all gets rendered by the browser, so short of full selenium testing are there any good options?
Would http://phantomjs.org/ help here? We are already using capybara-webkit
Many thanks in advance

Getting select2 to work with active admin

I am working with an app with Active Admin and needed to select multiple values from a select input, I have added the Select2 gem which adds all the relevant the JS and CSS with no issues but for some reason the select boxes seem to change their appearance slightly but not to the ful Select2 appearance, upon inspection the JS doesn't look like its added all the correct classes...... any ideas?
Here is my code:
active_admin.css.scss
//= require select2
#import "active_admin/mixins";
#import "active_admin/base";
active_admin.js
//= require select2
//= require active_admin/base
$(".select2able").select2({
placeholder: "Select a Partner"
});
activeadmin form
f.input :sponsors, as: :select, collection: Sponsor.all, input_html: {class: 'select2able'}
This is caused by Active Admin's decision to wrap its CSS styles inside .active_admin selector. As a result, most of third-party gem's CSS styles become less specific, and their appearance become broken.
For select2, and all gems whose CSS files are inside "stylesheets" folder, add the following lines at the bottom of active_admin.css.scss:
body.active_admin {
#import "select2";
}
This will give all of select2's styles body.active_admin selector, making them more specific than Active Admin's styles.
Problem solved, use chosen js instead of select2, works equally as well as select2 but without the issues in active admin.
https://github.com/gregbell/active_admin/issues/2267#issuecomment-19197807

How can I use Twitter Bootstrap to Customize a Rails 3 file_field input

I am using twitter's Bootstrap css framework and want to make the File Upload fields look better. With Paperclip I can do something as simple as:
<%= asset_fields.file_field :asset %>
And this renders:
<input id="recommendation_assets_attributes_3_asset" name="recommendation[assets_attributes][3][asset]" type="file" >
I can add classes just not sure what makes the most sense in Bootstraps case.
thanks
I just looked around some webs and found info that it's a custom control, so bootstrap have not added style for it to the core. But, fortunately, some one did it :). Take a look a this jasny bootstrap and jquery for upload with styled bootstrap also.

Rails3 twitter-bootstrap-rails with multiple layouts

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.

How do you visually distinct your Rails app for dev/test/production modes?

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 %>