error when using rinku - ruby-on-rails

How can I get rinku to run and the page to load properly?
Error message: uninitialized constant ActionView::CompiledTemplates::Rinku
Steps taken:
Installed rinku gem and rake-compiler and ran $ rake per the gem
developer's instructions
Inserted require 'rinku' into the controller file
Inserted the following into the view file <% text = "Go to http://www.abc.com or email me at dude#abc.com" %> and <%= Rinku.auto_link(text, mode=:all, link_attr=nil, skip_tags=nil) %>

The correct installation of Rinku in a Rails 3.2 app is:
Add gem 'rinku' to your Gemfile.
bundle install
Restart your Rails server, if it was already running.
Don't add require 'rinku' or bother with rake or the rake-compiler.
The Rinku.auto_link(text) should now work in your view. If the HTML renders as plain text, you may need to add raw or html_safe e.g.
<%= raw Rinku.auto_link(text) %>
or
<%= Rinku.auto_link(text).html_safe %>
Versions: rails 3.2.13, rinku 1.7.3

auto_link has been removed from Rails after version 3. Replacement gems are available.

Related

Will_paginate gem is not installing - Rails 4

for something reason will_paginate is not installed.
i have put the line
gem 'will_paginate', '~>3.0.6'
in my gemfile,
i even ran "gem install will_paginate" in the console.
it says installed sucessfully but using the instructions to check if will_paginate is indeed install returns false nil
reference:
>> defined? WillPaginate
>> ActiveRecord::Base.respond_to? :paginate
If any of these lines return nil/false, will_paginate has not properly loaded in your app.
and i get this error when implemented
undefined method `total_pages' for #<Post::ActiveRecord_Relation:0x007fa40773bc18>
UPDATE:
I specifically stated in my gemfile to install version 3.0.5 not the latest version(3.0.7) and the gem is loaded properly. BUT the error with the total_pages still remains.
more info:
controller:
#posts = Post.paginate(:page => params[:page])
view:
<%= will_paginate #posts %>
UPDATE 2:
FIXED the error (had a typo) BUT i cannot see visually the gem anywhere on the page.

Simple_Form f.button :button throws a "not a symbol" error

Rails: 4.0.0
Ruby: 2.0.0
According to
https://groups.google.com/forum/#!topic/plataformatec-simpleform/dxvrRaizMYk
and
https://github.com/plataformatec/simple_form/issues/814
But when I try that I get an error:
{:class=>"button"} is not a symbol
For line
= f.button :button
In my gemfile I have
gem 'simple_form'
Any thoughts?
Since Rails 4 support in SimpleForm will be introduced in version 3.0.0 which is not released yet you have to use it from master branch for now. This should fix your issue:
ruby
gem 'simple_form', github: 'plataformatec/simple_form'

Devise with Rails 4

The team behind Devise announced via blogpost
http://blog.plataformatec.com.br/2013/05/devise-and-rails-4/ that it was releasing a version that is compatible with Rails 4, calling it '3.0 rc'. In the same blog post, it also said it's releasing Devise 2.2.4.
I'm trying to build a Rails 4 app. when I did gem install Devise, it installed 2.2.4, not the version compatible with Rails 4.
Fetching: devise-2.2.4.gem (100%)
Which I assume from the comments in the blogpost about strong parameters is not going to be compatible with Rails 4.
I looked at Devise's github page but it's not obvious to me how to install the version compatible with Rails 4. Can you assist?
https://github.com/plataformatec/devise
Note, I tried
gem install devise --version 3.0.0.rc1
but it said
ERROR: Could not find a valid gem 'devise' (= 3.0.0.rc1) in any repository
ERROR: Possible alternatives: devise
Devise is now compatible with Rails 4 out of the box as of the time of this answer.
Our end goal is to have users be able to register, log in and log out of the website. We'll also create a small partial view letting us know if we're logged in or out.
Install the Devise gem.
Open up your Gemfile and install the Devise gem.
gem 'devise'
Then in your terminal run the bundle install command to install the gem.
$ bundle install
Run some Devise generators to set up the initial configurations.
Run this command from your terminal:
rails generate devise:install
This generator installs the initializer that configures all of Devise's available settings.
Generate your User model.
Next we need to generate our User model. I'm going to name it User but you can name it whatever you like, just replace User with Whatever.
rails generate devise User
rake db:migrate
Configure your default URL option for Development.rb
Inside of config/environments/development.rb, set the Action Mailer's default URL to localhost:
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
Make sure you have a root route declared in Routes.rb
You need to make sure that routes.rb has a default root route - if you don't have one, set it!
root to: 'home#index'
Create a partial view to see if we're logged in or not.
Inside of your views/layouts folder create a file named _user_widget.html.erb and copy this code in:
<% if user_signed_in? %>
<p>Welcome <%= current_user.email %></p>
<%= link_to 'Logged In [click to logout]', destroy_user_session_path, :method => :delete %>
<% else %>
<p>You are not signed in.</p>
<%= link_to 'Login', new_user_session_path %>
<% end %>
And invoke it within your layout (views/layouts/application.html.erb):
<!DOCTYPE html>
<html>
<head>
<title>FacebookAuthTest</title>
<%= stylesheet_link_tag "application", media: "all" %>
<%= javascript_include_tag "application" %>
<%= csrf_meta_tags %>
</head>
<body>
<p class="notice"><%= notice %></p>
<p class="alert"><%= alert %></p>
<%= yield %>
<%= render 'layouts/user_widget' %>
</body>
</html>
Make sure you stop and restart the server otherwise you will find all sorts of nasty bugs! It's always best to restart your local
server when you update your gemfile or change anything in the
environment configuration file.
With all this in place, you should be able to sign up, log in and log out from your very own Rails website.
If you have any questions feel free to leave a comment below and I'll try to help.
UPDATE SEPT 17th, 2013: The master branch is now compatible with Rails 4. No need to search for another version.
Looking at the github repo, it looks like you want version 3.0.0.rc (no 1). So you'll want
gem install devise --version "3.0.0.rc"
or, in your gemfile:
gem 'devise', '3.0.0.rc'
This installed it
gem install devise --pre
or
devise-3.0.0.rc.gem
At this point this version of the gem is what you would want to use
gem 'devise', '3.0.0'
gem 'devise', github: 'plataformatec/devise', branch: 'rails4'
Now that the 3.0 version is stable, you can just do:
gem install devise
or in your Gemfile:
gem 'devise'

Rails 3.1 issue with javascript_include_tag in application.html.erb

I've created a clean and simple Rails 3.1 application called demo1. It contains two controllers - hello and goodbye. I get the following error when I try to load http://localhost:3000/say/hello:
ActionView::Template::Error (
(in /home/me/dev/ruby/demo1/app/assets/javascripts/say.js.coffee)):
3: <head>
4: <title>Demo1</title>
5: <%= stylesheet_link_tag "application" %>
6: <%= javascript_include_tag "application" %>
7: <%= csrf_meta_tags %>
8: </head>
9: <body>
app/views/layouts/application.html.erb:6:in
`_app_views_layouts_application_html_erb___558576499_89622220'
The problematic line of application.html.erb is:
<%= javascript_include_tag "application" %>
When I created the application using Rails 3.0 this particular line was:
<%= javascript_include_tag :defaults %>
And this worked fine. In fact, when I change the application.html.erb to use :defaults everything works, but I want to use the new features of Rails 3.1.
I can't seem to turn up anything on Google around this, I guess because Rails 3.1 has just been released.
By the way, I'm following the first chapter in the Agile Web Development with Rails (4th edition) Updated for Rails 3.1 book.
Some environmental info that may help in answering this question:
$ cat /etc/issue
Ubuntu 10.04.2 LTS \n \l
$ ruby -v
ruby 1.9.2p290 (2011-07-09 revision 32553) [i686-linux]
$ rails -v
Rails 3.1.0
Contents of the say.js.coffee file:
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
Ok, I've figured out what the issue was, and so I'll answer my own question.
The problem was the app/assets/javascripts/application.js file contained commented out code. However, one of the commented out lines was as follows:
//= require_tree .
When I delete this line everything works fine.
Hope this helps. If someone can provide some insight as to why the underscore was causing the issue that would be great.
I just ran into this issue when starting a new RoR 3.2.1 app. The problem is that you are missing a JS runtime, which is because the line
# gem 'therubyracer'
in your Gemfile has that # in front of it. God only knows why they ship Rails with that line commented, because any tutorial that uses generate scaffold or similar will result in the asset compilation process tripping up over the generated coffeescript file.
The solution is to uncomment that line. Installing another JS runtime may also solve the problem. See e.g. ExecJS and could not find a JavaScript runtime.
The official ruby on rails guide says:
Compiling CoffeeScript to JavaScript requires a JavaScript runtime and the absence of a runtime will give you an execjs error. Usually Mac OS X and Windows come with a JavaScript runtime installed. Rails adds the therubyracer gem to Gemfile in a commented line for new apps and you can uncomment if you need it. therubyrhino is the recommended runtime for JRuby users and is added by default to Gemfile in apps generated under JRuby. You can investigate about all the supported runtimes at ExecJS.
Simply delete the 2 lines from application.js
//= require turbolinks
//= require_tree
I had the same problem running rails 3.1.1
Once I reinstated the following code in my Gemfile, my issue disappeared:
group :assets do
gem 'sass-rails', '~> 3.1.4'
gem 'coffee-rails', '~> 3.1.1'
gem 'uglifier', '>= 1.0.3'
end
gem 'jquery-rails'
This was placed in my Gemfile when initially setting up the project, i.e. using "rails new myapp".
Note that the in my template file I include:
<%= javascript_include_tag :application %>
Hope that helps
If you're on Windows and you used RailsInstaller to get your development going, you need to use that .bat file included with RailsInstaller to run your server. Also you can't use any CMD hook like conemu to start the server, unfortunately.
For the benefit of future Googlers, I went down a rabbit hole trying to install therubyracer until I stumbled upon this related post:
ExecJS::RuntimeError in rails 3.2.8 engine with javascript_include_tag
The link mentioned explains that ExecJS is configured incorrectly for Windows 8 out-of-the-box. In particular, the workaround described by pottsk did the trick for me.
https://github.com/sstephenson/execjs/issues/81#issuecomment-9892952
It involves changing the way that the cscript executable is run by ExecJS in %rubyinstall%\gems\2.0.0\gems\execjs-2.0.1\lib\execjs\runtimes.rb:
# JScript = ExternalRuntime.new(
# :name => "JScript",
# :command => "cscript //E:jscript //Nologo //U",
# :runner_path => ExecJS.root + "/support/jscript_runner.js",
# :encoding => 'UTF-16LE' # CScript with //U returns UTF-16LE
# )
JScript = ExternalRuntime.new(
:name => "JScript",
:command => "cscript //E:jscript //Nologo",
:runner_path => ExecJS.root + "/support/jscript_runner.js",
:encoding => 'UTF-8' # CScript with //U returns UTF-16LE
)
It goes without saying that this is not a permanent solution but it does get me up and running until the patch is incorporated.
Removing //= require_tree will just stop your javascript files from being loaded into rails. It will probably stop the error, but probably not what you'd like.
However, in my case, I had some .js.coffee files with incorrect indenting. Once I fixed this (by deleting them), it worked.
Another thing you can try which worked for me is to add the json (and perhaps also the yajl-ruby) gem to your Gemfile. I don't really understand why they weren't already installed before because:
rails depends on actionpack
which depends on sprockets
which depends on json and tilt
and tilt depends on yajl-ruby
Yet, somehow, it seems many of the dependent gems were not installed!?
In case of using linux(Ubuntu linux like mine), install javascript runtime. The best is issue the below command to install,
apt-get install nodejs
or else, for each and every new creation of rails project, add
gem 'therubyracer' to your gemfile and run bundle install
devise_scope :user do
get 'sign_out', :to => 'devise/sessions#destroy', :as => :destroy_user_session
end
If your routes.rb has this above line just delete it and run. This is what corrected my problem.
modify generator file (application.html.erb.tt) as the following:
<%= javascript_include_tag "application", "data-turbolinks-track" true %>
<%= javascript_include_tag :default, "data-turbolinks-track" true %>
Just REMOVE the following line (Line no. 6) from generator file (application.html.erb) :
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
please update me if there is any drawback to remove this line
Thanks
I have this issue in Rails 4, and if I switch it to 'defaults' rather than 'application', it works, just as the OP says. But this is in an external Gem that I'd rather not edit. I have found that if I force my Gemfile to use version 1.8.0 of coffee-script-source, do a bundle install, and start the server, then everything works fine.
Adding the gem 'therubyracer' fixed the issue.
I was getting the error only after adding external js file through <%= javascript_include_tag %>

Trying to call methods from gems in a view, getting "no such file" error

I have just installed a base installation of rails and have edited the main page to view some basic html and a link to create a new blog post via ruby in the corresponding 'erb' file. I am trying to add some additional ruby commands on this same page via <%= %> tags.
<h1>Hello, Rails!</h1> <%= link_to "My Blog", posts_path %>
<p>
<%= require 'rubygems' %>
<%= require 'simplegeo' %>
<%= SimpleGeo::Client.set_credentials('token', 'secret') %>
<%= a = SimpleGeo::Client.get_context(coordinates,coordinates); a %>
</p>
When I load this page , I get the following error: no such file to load -- simplegeo
Can someone point me in the right direction? Many thanks!
In Rails 3, you need to add this gem to your "Gemfile" .. follow this: http://gembundler.com/rails3.html
Remove this completely.. Never do this in your views
<%= require 'rubygems' %>
<%= require 'simplegeo' %>
Once you restart your rails server, if you added "simplegeo" to your gemfile, it'll be auto-required.
Move this to your controller to start
SimpleGeo::Client.set_credentials('token', 'secret')
#simple_geo_client = SimpleGeo::Client.get_context(coordinates,coordinates)
Then in your view, you can access any variable that starts with #
To get started in Rails, check out http://railsforzombies.org/
In rails 3.x, you use Bundler to specify gems. No need to require, especially in views.
Correct way is:
Open Gemfile
Set/List required gems inside using format:
source :rubygems
gem "simplegeo"
gem "some_other_gem"
Run bundle install (or just bundle) command in console.
now restart your server and gems are auto required.
Check out Rails guide on how to start.
Most probably you did not install Simplegeo gem properly, or did not attach it correctly in you IDE.

Resources