How to install 'Ckeditor' for 'Active Admin' with 'Rails 3.1' - ckeditor

I looking for how to install Ckeditor for Active_Admin
I already installed Ckeditor and I have put this line in my 'initializers/active_admin.rb' file.
# To load a javascript file:
config.register_javascript
'ckeditor/config.js'
And the line
config.autoload_paths += %W(#{config.root}/app/models/ckeditor)
in my 'config/application.rb'
In the begining the 'config.js' file wasn't loaded because when I install Ckeditor gem it creates a folder named Ckeditor in public/javascripts but with rails 3.1, I had to move this folder into assets/javascripts...
That's what I've done.
Now the file "config.js' is loaded.
But now I don't know what I have to do next

Rails 3.2
activeadmin-0.4.3
in 'initializers/active_admin.rb' file.
config.register_javascript 'ckeditor/ckeditor.js'
config.register_javascript 'ckeditor/init.js'
in form
= f.cktext_area :text

If your're using the assets pipeline with external host server you have to hack a little bit.
Your assets/javascripts/active_admin.js should look like this:
//= require active_admin/base
//= require_self
//= require ckeditor/ckeditor
//= require ckeditor/init
var CKEDITOR_BASEPATH = 'http://assets.yourdomain.com/assets/ckeditor/';
Then you're good to go.

Add
var CKEDITOR_BASEPATH = '/assets/ckeditor/';
to the start of your ckeditor.js file.
I believe you are having an issue with the new location of the files in rails 3.1. Make sure all your ckeditor files are located in the javascript/ckeditor folder (or modify the link accordingly).
See http://docs.cksource.com/CKEditor_3.x/Developers_Guide/Specifying_the_Editor_Path

You can also use in your forms
f.input :name, :as => :ckeditor

There is a page in the oficial wiki for this task.

Related

Rails wicked_pdf, convert page as pdf

I have a normal Rails layout which is my normal Site.
I want a Button on this page to convert/transform this page into
a PDF file.
I want to do it with this gem:
https://github.com/mileszs/wicked_pdf
I added gem 'wicked_pdf' to my Gemfile, but now how can I convert the actual page?
Here's what I did to use wicked_pdf:
# Gemfile
gem 'wicked_pdf'
gem 'wkhtmltopdf-binary' # if you need the binary too
Then run
$ bundle install
$ (bundle exec) rails g wicked_pdf # generates the initializer
Then you can configure global settings in config/initializers/wicked_pdf.rb as stated in the wicked readme on github.
Rails 4 already knows the pdf mime type, but in older versions you'll probably need to register pdf as a mime type:
# config/initializers/mime_types.rb
Mime::Type.register "application/pdf", :pdf
In your controller
respond_to do |format|
format.html
format.pdf do
render pdf: "your-filename"
end
end
Then you put a view under app/views/<your-view>/<controller-action>.pdf.erb with the content you wan't.
To reference this by a link you can do something like:
= link_to "Get PDF", your_path(format: :pdf)
Does this solve your question?
Please follow the below link. Its a details tutorial, this will make your life easier:
http://dchua.com/2014/10/30/generate-pdfs-with-html-templates-in-rails/
Note
If you don't want to have your pdf views separately and want to use the same html view, then please use
template: invoices/show.html.erb
instead of
template: invoices/show.pdf.erb

Moving blog articles location in Middleman

I'm using the Middleman Blog gem for my site, but by default it appears the blog articles need to be located in /source which isn't particularly nice when looking at the tree in vim and trying to locate one of the other files in there (a template for instance).
From looking at the documentation I can't see if there is any way of moving the blog articles so they are stored somewhere else such as a blog_articles folder or similar.
Is this possible?
Put the following in your config.rb file.
activate :blog do |blog|
blog.permalink = ":year-:month-:day-:title.html"
blog.sources = "blog_articles/:title.html"
end
Assuming you have a post 2012-01-01-example-article.html.markdown stored in the folder source/blog_articles.
You should now see the post with this URL: http://localhost:4567/2012-01-01-example-article.html. (You might have to restart middleman when changing the config.rb file.)
Please note that I also had to set blog.permalink, the blog.sources setting alone didn't do the trick.
A bonus tip: I have activate :directory_indexes in my config.rb file. This setting gives you nice looking URLs, without the .html part.
If you want the same for your blog posts you can drop the .html from your blog.permalinksetting. Like so:
activate :blog do |blog|
blog.permalink = ":year-:month-:day-:title"
blog.sources = "blog_articles/:title.html"
end
Now you can see your post with this URL: http://localhost:4567/2012-01-01-example-article.
I messed with the middleman-blog extension, but gave up for its relative opaqueness. In looking at the source, though, it appears the prefix option might do the trick for you? It's somewhat unclear whether the prefix is a URL prefix or a local path prefix:
activate :blog do |blog|
blog.prefix = "/blog_articles"
end
From looking at the code it transpires there is a :sources option which you can use. If you poke around in the source there is an example of this:
https://github.com/middleman/middleman-blog/tree/master/fixtures/article-dirs-app
The solution above worked for me when I made the following changes to the permalink / source config options:
blog.permalink = ":title.html"
blog.sources = "posts/:year-:month-:day-:title.html"
The permalink is the location which it will appear in the web browser url where the source is the locations of the posts.
Using middleman 3.2.1
I made blog folder inside source directory. Then i make posts directory and moved all my posts there. source/blog/posts/...
and then inside config.rb
activate :blog do |blog|
..........
blog.permalink = "blog/:year/:month/:day/:title.html"
blog.sources = "blog/posts/:year-:month-:day-:title.html"
.........
end

Requiring a file in ROR

I have a controller which wish to include a file in another folder, how do I do that? I am using Ruby 1.9.2 and Rails 3.2.6. Thanks
Controller file is in
/project/app/controllers/examples_controller.rb
and the required file is in
/project/example_folder/example.rb
require File.join(Rails.root, "example_folder", "example")
assuming /projects/ is your rails application root folder
You can auto load custom directories with classes and modules you want to be.
So you can Edit config/application.rb
# Custom directories with classes and modules you want to be autoloadable.
config.autoload_paths += %W(#{config.root}/example_folder)
It would be something like this:
require "#{Rails.root}/example_folder/example.rb"
just before the declaration of your controller.
according to here
more info here Why does Ruby 1.9.2 remove "." from LOAD_PATH, and what's the alternative?
requie_relative '../../example_folder/example.rb'

Rails 3.1.3 unable to access the file inside assets/javascripts folder

I have put fancybox (jquery plugin ) inside the assets/javascripts/includes/jquery.fancybox-1.3.4
Before this location i also tried to put it under /vendor/assets/stylesheets/jquery directory.
I am getting this weird error & why isn't rails able to get the particular file when its right there.
------------- Development Log ----------------
Started GET "/vendor/assets/stylesheets/jquery.fancybox-1.3.4/fancybox/jquery.fancybox-1.3.4.pack.js" for 127.0.0.1 at 2011-11-25 13:30:42 -0800
ActionController::RoutingError (No route matches [GET] "/vendor/assets/stylesheets/jquery.fancybox-1.3.4/fancybox/jquery.fancybox-1.3.4.pack.js"):
Rendered /Users/jayparteek/.rvm/gems/ruby-1.9.2-head#default/gems/actionpack-3.1.3/lib/action_dispatch/middleware/templates/rescues/routing_error.erb within rescues/layout (0.5ms)
-------------- Log 2 -------------------------
ActionController::RoutingError (No route matches [GET] "/vendor/assets/javascripts/fancybox-1.3.4/jquery.fancybox-1.3.4.pack.js"):
Simply use the fancy box gem https://github.com/hecticjeff/fancybox-rails
Rails doesn't load your */assets/javascripts tree automatically, just the files in that directory. And by default, it will only precompile application.js and anything with a non .js extension.
I would recommend you rename the fancybox file to just fancybox-1.3.4.js. With Rails 3.1, assets are concatenated and minified before output, so there's not much need to even use the minified version, though it won't hurt anything if you do.
You should put jQuery plugins directly in vendor/assets/javascripts/, then include them into the appropriate file (probably application.js) in app/assets/javascripts, like so (assuming application.js):
//= require jquery
//= require fancybox-1.3.4
//= [any other requires here]
//= require_self
Then you use javascript_include_tag 'application' in your layout. Voila!

Netzke on RAILS 3.1

I am newbe here about Netzke..
I am trying to follow the installation process in the Netzke web
site http://www.netzke.org and also from the git Netzke-core site..
I just download the EXT JS 4.0.2 zip file from Sencha, extract it and try to symbolic link the ext JS code to <railsdir>public/extjs directory..
and with the rails 3.1, I try also to link it to <railsdir>/app/assets/
javascripts and also <railsdir>/app/assets/stylesheets..
But it still does not work, because it doesn't find the file /extjs/resources/css/ext-all.css..
Please can you help which path or directory to link the EXT JS code to?
Linking the /code/sencha/EXT-4.0.2a to public/extjs
, that what I have done, but no success..
set config.assets.debug = false in environment/development.rb file
it will work with Netzke
I'm just newbie for Netzke too. I think your problem with model_name method is that you Use GridPanel without a config model to it. You should do something like this:
<% netzke :some_component, :class_name => "Netzke::Basepack::GridPanel", :model => "YourModel" %>
It should work :)

Resources