Activeadmin with Tinymce CDN - ruby-on-rails

I'm fairly new to rails. I have a Rails 3.2.13 app running ActiveAdmin. I'm trying to integrate tinyMCE as my editor for the text areas. I want to use the quick install CDN hosted by Cachefly.
I'm able to add the reference to the minified tinymce javascript on the cdn by adding
config.register_javascript 'http://tinymce.cachefly.net/4.0/tinymce.min.js'
that renders the script tag below in my header.
<script src="//tinymce.cachefly.net/4.0/tinymce.min.js"></script>
How can I add the initializer script below to my head in activeadmin on all the pages?
<script>
tinymce.init({selector:'textarea'});
</script>
I'm a Rails noob. It's probably something simple, but I searched everywhere and I can't seem to figure it out.
Any help would be greatly appreciated.

You can simply add a javascript file as well after you add tinymce to the config. So it would look like:
config.register_javascript 'http://tinymce.cachefly.net/4.0/tinymce.min.js'
config.register_javascript 'admin/custom.js'
Where custom.js would be located in:
app/assets/javascripts/admin/custom.js
And the contents would be your desired js code that will execute on all pages:
(function() {
tinymce.init({selector:'textarea'});
})();

Related

Rails vendor asset templates

I was wondering if there was a good solution for getting vendor html templates into the rails asset pipeline. Right now I'm making it work by putting the two templates I need in /public
I used Bower to install angular-ui-bootstrap and I can require the javascript fine from application.js after adding the config.assets.path in application.rb.
How do you do the same for the html templates that the angular module needs? The JS is in /src, the template is in /template.
Not sure I understand the question. You can add them as template strings js in assets/javascripts but it could get a little messy.

Simple form bootstrap for rails 4

I'm using 'bootstrap-sass' and 'simple_form' gems on Rails 4. When I run this generator: rails g simple_form:install --bootstrap I get a message that says:"Be sure to have a copy of the Bootstrap stylesheet available on your
application, you can get it on http://twitter.github.com/bootstrap."
Why do I need a copy of the Bootstrap stylesheet and what is THE stylesheet? Doesn't the 'bootstrap-sass' gem handle that? I went to the link provided but got a 404 error. If anyone can kindly explain what I need to do it would be greatly appreciated! I am fairly new to Rails, so apologize in advance if it's not a very good question. Thank you!
Here is the real link to Bootstrap. Yes, the bootstrap-sass gem will include Bootstrap's javascript, CSS, and fonts into your application, just make sure you include them.
In your javascripts/application.js (docs)
//= require bootstrap
Create a file, say master.css.scss and import the Bootstrap CSS and fonts like so (docs):
#import "bootstrap";
When you specified the extension --bootstrap when installing simple_form, you essentially said, hey I have bootstrap and want my forms to be styled the way bootstrap styles them. It will also add the appropriate HTML to the form and inputs to adhere to Bootstrap. So it automatically generated the file config/initializers/simple_form_bootstrap.rb. Now when you create a form using simple_form_for (please read their docs..they are very extensive), it will be styled like Bootstrap.
So, to sum it up, you need Bootstrap if you want your forms to be styled and set up, with Bootstrap html and css, like Bootstrap forms. If you didn't want Bootstrap, you could have just ran the simple_form generator like this: rails generate simple_form:install.
when you ran this code:
rails g simple_form:install --bootstrap
you are integrating simple_form with bootsrap. and therefore, what the message is telling you is to add bootstrap to your stylesheets folder of your application. The stylesheet folder is where you keep your css files. Here is it's directory structure:
app/assets/stylesheets
bootstrap download comes with css, javascripts, and fonts folders. the bootstrap files inside the css folder will go under app/assets/stylesheets.
of course, if you are not using bootstrap in your project, then you are running the wrong generator. you should simply run:
rails generate simple_form:install
and not append --bootstrap to the generator.

rails 3.2.9 + ember.js 1.0.0-pre.2 keeps giving template not found error, any clue?

Is there a sample Rails backend + ember.js 1.0.0-pre.2 app to refer.
My application is broken after upgrade.
I read about the named handlebars but there seems to be an issue.
If I write in index.html.haml
<script type="text/x-handlebars" data-template-name="application">
<h1>HI</h1>
</script>
Ember.TEMPLATES has a template named application
if I write a file application.handlebars with same content, I get the error Unable to find template 'application'
Is there any path configuration which has to be done which is missing. Please help.
I'm maintaining an up-to-date Rails / ember example you could reference:
https://github.com/dgeb/ember_data_example
Are you using ember-rails to compile your templates? Of course, you'll also need to require your templates in your application.js if you're using the asset pipeline.
Removed handlebars-assets Gem from Gemfile it used to work till 1.0.pre, it was generating handlebars which were not compatible to Ember code. Ember adds all templates to Ember.TEMPLATES, it was adding into HandlebarsTemplates.
Actually handlebars-assets was never needed. Thanks everyone for help.

add external style sheet in rails project

I am using Rails 3.2.1. How do I add external style sheets in my rails application?
I've tried the following answers to no avail:
How do I link to an external stylesheet in Ruby on Rails? - but the link given in the answer is not working.
How do I use CSS with a ruby on rails application? - which says to add stylesheet in public/stylesheets, but I do not have folder named public/stylesheets. I do have a public folder, but I have stylesheets folder under /vendor/assets.
css #import external style sheet - but it's unclear.
I'm just going to assume you're already using something like this in your layout:
stylesheet_link_tag 'application'
If you want to refer to an external stylesheet then all you need to do is pass in the url.
stylesheet_link_tag 'application', 'http://yui.yahooapis.com/2.8.1/build/reset/reset-min.css'
If you want to include the actual files in your codebase:
app/assets/stylesheets is where you should place your main css files.
vendor/assets/stylesheets is where you should place the css files for any plugins that you might have.
It's the same for js files. For example your application.js would go in app/assets/javascripts and a jquery plugin like timeago.js would go in vendor/assets/javascripts.
After looking for a solution to this problem for a while, I found this step by step tutorial which explain how to implement a bootstrap theme to a rails app => http://www.notch8.com/implementing-a-bootstrap-theme/
You can apply this to other CSS and JS templates than a Bootstrap one.
Hope this help (sorry if I make english mistakes)

Rails 3 project, installed jquery-rails gem, but getting "Ajax is not defined"

I'm a rails newbie trying to follow a howto on how to perform some Ajax calls (after switching to jQuery), but I've run into a problem.
Whenever I trigger the ajax code (new Ajax.Request()), I get "Ajax is not defined" in firebug. Anyone with more skills than me know what's up here?
update:
For anyone else having this problem, the code that was generating the the above code, was a call to remote_function()
What I have done to set things up:
Added "gem 'jquery-rails', '>= 1.0.12'" to my gemfile, and run bundle install
Run rails generate jquery:install
My public/javascripts/ folder thus has the following files:
application.js
jquery.min.js
jquery-ui.min.js
jquery.js
jquery-ui.js
jquery_ujs.js
The scripts included in my HTML look like this:
<script src="/javascripts/jquery.js?1312911234" type="text/javascript"></script>
<script src="/javascripts/jquery-ui.js?1312911234" type="text/javascript"></script>
<script src="/javascripts/jquery_ujs.js?1312911234" type="text/javascript"></script>
<script src="/javascripts/application.js?1312911234" type="text/javascript"></script>
I'd guess that your tutorial uses Prototype as Ajax.Request is for Prototype, you should be using $.ajax with jQuery. And switching to a jQuery based tutorial might be a good idea too.
You say that you're using remote_function but that's Prototype-specific:
Usage
To be able to use these helpers, you must first include the Prototype JavaScript framework in your pages.
Prototype used to be the default JavaScript library for Rails so I suspect that PrototypeHelper is a leftover. You probably want to look at things like the :remote option on link_to and similar for new code.

Resources