CKeditor in Ruby on Rails - ruby-on-rails-3

I installed Ckeditor following the instruction in this repository
I created a simple rails application adding
gem 'ckeditor'
to the Gemfile and then running bundle install from command line.
I created a scaffold with only one text field. I wanted to have a cktext_area rather than a normal text_area in the create/update action.
However, I get this error
undefined method 'cktext_area' for #<ActionView::Helpers::FormBuilder:0xb66fe5a8>
if I substitute the form text area with this
<%= javascript_include_tag :ckeditor %>
<%= f.cktext_area :name%>
I ran the installation as written in github, it seems it isn't able to find the appropriate helper. Even if I try to insert cktext_area_tag("test_area", "Ckeditor") it isn't able to find the correct helper.
I'm using Rails 3.1.3

Hey first I also got this error and then when i restarted the server everything worked fine.
Try it.Hope it gets working.

Related

gmap4rails - can't find file underscore / Gmaps is not defined

I am following the simple tutorial here: https://github.com/JonKernPA/gmaps
I keep getting the error:
couldn't find file 'underscore'
(/app/assets/javascripts/application.js:16)
with the following line highlighted:
<%= javascript_include_tag "application", "data-turbolinks-track" => true %>
I tried following the suggestions posted in
Gmaps is not defined in rails 4 + gmaps4rails 2.0.3
and I get the same error with the error with the same line highlighted.
When I try to remove the line
<%= javascript_include_tag "application", "data-turbolinks-track" => true %>
from application.html.erb, I get the error "Gmaps not found"
Any help appreciated, thanks.
Github link: https://github.com/chiefkikio/circus/
Found a solution. Had to install gem 'underscore-rails' and then bundle it and restart the rails server.
Not a tutorial project, but I use gem 'underscore-rails' (cf https://rubygems.org/gems/underscore-rails) to satisfy gmaps4rails' dependence.
The minified version of Underscore has this line at the end of the file:
//# sourceMappingURL=underscore-min.map
Chrome's developers tools will try to download underscore-min.map when encountering this line. Users won't see this error, unless they open developer tools.
If you want to get rid of this error, either add underscore-min.map to your project (https://github.com/jashkenas/underscore/blob/master/underscore-min.map) or remove that line from underscore.min.js
I also faced the issue and this is what was the reason for me:
The order of required files in my application.js was wrong. I required
//= require_tree . before gmaps. And since I didn't wait until page load in my controller_name.js file, it was loaded first, trying to use Gmaps before the latter was defined.. I thought it might help, but.. I run into another couple issues with ".. is not defined". After small research here is the solution:
wrap you whole custom js in callback for window.load event. I used it with this line:
google.maps.event.addDomListener(window, "load", callback)
Hope this will help

How to set sinatra-authentication to use erb instead of haml?

I'm trying to set up the sinatra-authentication gem in a simple sinatra app, and running into an issue where sinatra can't find the correct views. I understand that sinatra-authentication uses haml by default, but I'm using erb in this app.
This in mind, I found in the sinatra-authenticaiton docs that there is a setting which allows you to change the template engine, by adding the following to your app file:
configure do
set :template_engine, :erb # for example
end
I've added this to my app.rb file, and sinatra is still looking for the signup.haml when I try to hit the /signup route in my app.
A couple of notes:
I've included the gem in my Gemfile, and successfuly run a bundle install on my app.
source 'https://rubygems.org'
gem 'sinatra'
gem 'data_mapper'
gem 'pg'
gem 'dm-postgres-adapter'
gem 'sinatra-authentication'
I saw something in the documentation that suggested that I may need to specify the location of my view files, so I added the following to my configuration block.
set :sinatra_authentication_view_path, Pathname(__FILE__).dirname.expand_path + "views/"
**I think I've required the gem accurately in my app file by adding
require "sinatra-authentication"
use Rack::Session::Cookie, :secret => 'mys3cr3tk3y'
This gist is a current representation of my app.rb file in the root of my sinatra app. https://gist.github.com/rriggin/5378641#file-gistfile1-txt
Here is a screenshot of the error sinatra throws: http://cl.ly/image/0y041t0K3u3O
When I run the app locally, a 'dm-users' table is created in my local db as expected.
Is there another configuration setting that I'm missing in order to get sinatra-authentication to properly look for the erb templates rather than haml files. Any help would be greatly appreciated.
Thanks
The specs don't test that the template_engine setting works, and looking at the way the setting is called, I believe it's not correct, i.e.
send settings.template_engine, get_view_as_string("index.#{settings.template_engine}"), :layout => use_layout?
might better work as:
send app.settings.template_engine, get_view_as_string("index.#{app.settings.template_engine}"), :layout => use_layout?
that's what I reckon. If you fork the project, change the line and add it to your Gemfile and it works then consider writing a quick spec for it and you'll have improved the mainline of that project as well as fixed your problem.

Rails with Jader gets 'failed to require "fs"' error

I am trying to use client side Jade templates that are precompiled by Ruby on Rails and available through JST.
I added the jader gem
gem "jader", "~> 0.0.8"
In configuration/initializers I created an initializer called jader.rb that contains:
Jader.configure do |config|
config.views_path = Rails.root.join('app','assets','javascripts','views')
config.mixins_path = Rails.root.join('app','assets','javascripts','mixins')
end
In app/assets/javascripts/views I added an index.js.jst.jade file
Hello World!
Lastly in my javascript file I have:
$('#app-content').append(JST["views/index"]());
When I run Rails and browse to the page triggering the code I am getting the following error:
failed to require "fs"
(in /my-project/app/assets/javascripts/views/index.js.jst.jade)
I understand that the problem is that jade is a node.js project and the require function is having a problem. How do I fix the require error?
If you are looking at using Jade templates only on the client side (with Rails asset pipeline), I recommend https://github.com/inossidabile/jade
It's likely there is an error in your index.jade template.
From the jade rails-fix pull request here, ExecJS used by rails does not support require("fs") and will throw 'failed to require "fs" even if it's a template error. Hopefully this should point you in the right direction.
To debug, you can replace the content of index.jade template with with a 1-liner jade placeholder to see if it renders well. Alternatively, try it out rendering the index.jade template with a nodejs server if possible to be sure the template renders without any whinning.

Rails Active Admin resource problem

I recently have watched railscast 284 about active admin and wanted to implement it into my web app, however I am running into an issue when I add a resource. I get the following message every time I try to navigate to the created tab:
NameError in Admin::LoadsController#index
undefined local variable or method `per' for []:ActiveRecord::Relation
Rails.root: /Users/thomascioppettini/rails_projects/want-freight
Application Trace | Framework Trace | Full Trace
Request
Parameters:
{"order"=>"id_desc"}
Show session dump
Show env dump
Response
Headers:
None
The only thing I can think of that may affect the application is adding a recaptcha to devise, which active admin depends on.
For me, it looks like this is a pagination problem. What gem are you using? You should give as more details about your settup. Can you show us your resource file from admin directory? What version of rails and what ActiveAdmin are you using ?
If you are using the will_paginate gem, set the version to 3.0.pre2. I was using ~>3.0.pre2, which auto-updated to 3.0.2 when I ran a bundle update Reverting fixed the issue. If you're using Bundler, the line is this:
gem "will_paginate", "3.0.pre2"
I agree with Dawaid. It is a pagiantion error. Add "Kaminari" gem to you Gemfile. According to active admin docs, it is using kaminari for pagination.. will_paginate will also work for you as swilliams described...
As I understand active_admin doesn't support will_paginate anymore. But if you don't want to rewrite your pagination to Kaminari you can fix this problem with putting some code to initializers
# config/initializers/will_paginate.rb
if defined?(WillPaginate)
module WillPaginate
module ActiveRecord
module RelationMethods
alias_method :per, :per_page
alias_method :num_pages, :total_pages
end
end
end
end
module ActiveRecord
class Relation
alias_method :total_count, :count
end
end

Devise RPX Connectable error undefined method user_session_url

I am trying to install the devise_rpx_connectable gem functionality into my application. Everything seemed to install fine but when I try to call
<%= link_to_rpx "Signin using RPX!", user_session_url %>
I get an undefined method error on user_session_url
Any ideas on what is causing this?
It turns out I had messed up on the initial generation of the devise model. I backed out and re-did it and everything started to work.