I'm trying to use Sass engine in a controller like in this blog post. But Rails (2.3.4) ActiveSupport can't load it because of an error:
ArgumentError (Anonymous modules have no name to be referenced by):
haml (3.0.25) lib/sass/script/color.rb:19
haml (3.0.25) lib/sass/script/literal.rb:10
haml (3.0.25) lib/sass/script/string.rb:1
haml (3.0.25) lib/sass/script/operation.rb:2
haml (3.0.25) lib/sass/script.rb:5
haml (3.0.25) lib/sass/engine.rb:22
app/controllers/stylesheets_controller.rb:1
Here's the code in Sass::Script::Color
class << self; include Haml::Util; end
I've tried with the latest Haml version and also version 2.2.24 with the same result. Is there a compatible version? Is there a problem on my side?
Finally it was quite stupid, the Sass::Script::Color file wasn't requiring Haml::Util, so I had to do it myself:
require 'haml/util'
require 'sass/engine'
Related
I have a Rails 4.2 framework and use Kaminari to paginate. Everything works great, but I want to test everything with Capybara, thus I run into the page conflict. So I wanted to rename the page_method_name of Kaminari and followed the guide from them:
$ bundle exec rails g Kaminari:config
This results in this file
app/config/initializers/kaminari_config.rb
Kaminari.configure do |config|
config.page_method_name = :plant
end
In which I simply uncommented the config.page_method_name and set it to :plant (as an example from the Kaminari docs to avoid any reserved method name conflicts for something like :kaminari_page).
Then I adjusted the appropriate controller to
def index
#q = Interaction.published.order(updated_at: :desc).limit(200).ransack(params[:q])
#selection = #q.result
#interactions = Kaminari.paginate_array(#selection).plant(params[:page]).per(10)
respond_to do |format|
format.html
format.js
end
end
I restarted everything and got this error when visiting the
undefined method `plant' for #Kaminari::PaginatableArray:0x00005568fb42ba30
Gemfile.lock:
kaminari (1.2.1)
activesupport (>= 4.1.0)
kaminari-actionview (= 1.2.1)
kaminari-activerecord (= 1.2.1)
kaminari-core (= 1.2.1)
kaminari-actionview (1.2.1)
actionview
kaminari-core (= 1.2.1)
kaminari-activerecord (1.2.1)
activerecord
kaminari-core (= 1.2.1)
kaminari-core (1.2.1)
I was then googling around and also added require 'kaminari' (which does not make so much sense, because I did not get the uninit constant error) and also included the Kaminari configure section into the class Application < Rails::Application inside config/application.rb.
Nothing worked, always the same error.
You show your files location as app/config/initializiers/kaminari_config.rb. If that is the actual location of your file it fully explains why the method doesn't exist. The location should be app/config/initializers/kaminari_config.rb. With the location you specified it wouldn't be automatically loaded when the app starts.
If the location you showed is just a type then that wouldn't be the cause, but if you didn't include Capybara into the global object, which you shouldn't be doing anyway, then you wouldn't have a name collision. Current versions of Capybara issue a warning when you do include it into the global object specifically for this reason.
Also is there any reason you're grabbing all the results and then paging them, rather than using the page (or plant) and per scopes that would be defined on Interaction?
Trying to add Gravatar to my app
but get "could not find generator gravtastic" on the command line
added gem 'gravtastic'
ran bundle install
Using warden (1.2.3)
Using devise (3.1.2)
Using foreigner (1.6.1)
Installing gravtastic (3.2.6)
Using hike (1.2.3)
Using jbuilder (1.0.2)
Using jquery-rails (3.0.4)
Using subexec (0.2.3)
restarted server
rails g gravtastic:install
Could not find generator gravtastic
Do you need to run a generator?
I think you just have to do:
class User < ActiveRecord::Base
include Gravtastic
gravtastic
end
The documentation doesn't mention the gravtastic generator.
I'm trying to use the activerecord-import gem and I've followed the directions on the wiki to a tee but I'm getting a NoMethodError: undefined method 'import' for #<Class:0x8b009b0>. Here's my code (basically the same as the example from the wiki)
class ExampleCode
def self.testing
orders = []
10.times do |i|
orders << Order.new(:raw_data => "order #{i}")
end
Order.import orders
end
end
I call the method like so:
ExampleCode.testing
I've tried on windows, linux, with a sqlite database, a mysql database and still no luck. And I'm certain I have the gem installed:
actionmailer (3.2.6, 3.2.3, 3.2.1, 3.2.0)
actionpack (3.2.6, 3.2.3, 3.2.1, 3.2.0)
activemodel (3.2.6, 3.2.3, 3.2.1, 3.2.0)
activerecord (3.2.6, 3.2.3, 3.2.1, 3.2.0)
activerecord-import (0.2.10)
activerecord-oracle_enhanced-adapter (1.4.1)
activerecord-sqlserver-adapter (3.2.1)....
I even tried to use require (which shouldn't be necessary when the gem is installed. I haven't seen this come up anywhere else so I fear I must to missing something very obvious
You'll have to import active_record and activerecord-import
i.e.
require active_record
require activerecord-import
(as mentioned in the wiki)
The reason being, ruby won't know about it unless you explicitly import those libraries. In case of a rails project, rails imports all gems mentioned in the Gemfile for you.
I ran into the same thing; turns out that for me at least I had the gem included within a test block in the gemfile. make sure that when you include it it's not just limited to one app environment in the gem file.
I just upgraded my Rails site from Rails 2 to Rails 3.2.
On my old controller I had:
class Foo::BarController < ApplicationController
layout nil
...
end
However now that I upgraded to Rails 3 it seems I need to change that to:
layout false
The documentation on Rails Guides claims that layout nil should work fine:
Layout declarations cascade downward in the hierarchy ...
class OldPostsController < SpecialPostsController
layout nil
I have the following relevant gems in my Gemfile.lock
GEM
actionpack (3.2.6)
activemodel (= 3.2.6)
activesupport (= 3.2.6)
builder (~> 3.0.0)
erubis (~> 2.7.0)
builder (3.0.0)
erubis (2.7.0)
haml (3.1.6)
jquery-rails (2.0.2)
railties (>= 3.2.0, < 5.0)
Is this a documented change somewhere, or is it a related gem monkey patching something?
The API explains it like this:
If the specified layout is:
a string: the string is the template name
a symbol: call the method specified by the symbol, which will return the template name
false: there is no layout
true: raise an ArgumentError
nil: force default layout behavior with inheritance
So the meaning of nil changed from no layout to "force default layout behavior with inheritance". Seems the explanation in Rails Guides is incorrect.
I keep getting the following error when sending a simple e-mail via ActionMailer in Rails:
NoMethodError: undefined method `encode!' for "Hello":String
This is triggered whenever the following is run:
def hello_world_email()
mail( :from => "me",
:to => "you,
:subject => "Hello World"
)
end
From researching this, it looks like it's caused by the differences between Ruby 1.8.7 and 1.9.*, which has built-in character encoding support.
Is there any way of getting ActionMailer to work with Ruby 1.8.7 and avoid this issue? (I can upgrade Ruby on my machine, but I can't do the same for everyone else working on the project). Given that the whole of Rails 3.0.9 (of which ActionMailer is a part) is meant to work with Ruby 1.8.7, I keep thinking that there must be a way...
Note: My exact version of Ruby is ruby 1.8.7 (2009-06-12 patchlevel 174) [universal-darwin10.0] (pre-installed on OSX).
You may have an issue with using Ruby 1.8 and having a constant Encoding defined by a gem.
For example we found an issue with a class that was including REXML at a global scope.
The line in question in the library was:
value.encode!(charset) if defined?(Encoding) && charset
This is checking for a global constant called Encoding. (Which could be defined in any gem at global scope.) Our problem was actually the include which then made REXML::Encoding available everywhere as Encoding. You could try grepping or acking your codebase for "module Encoding" or "class Encoding".
Hope this helps.
The stack trace below defines the problem.
NoMethodError: undefined method `encode!' for "Generate":String
mail (2.2.19) lib/mail/fields/unstructured_field.rb:169:in `encode'
mail (2.2.19) lib/mail/fields/unstructured_field.rb:138:in `fold'
mail (2.2.19) lib/mail/fields/unstructured_field.rb:108:in `wrapped_value'
mail (2.2.19) lib/mail/fields/unstructured_field.rb:70:in `do_encode'
mail (2.2.19) lib/mail/fields/unstructured_field.rb:52:in `encoded'
mail (2.2.19) lib/mail/field.rb:123:in `send'
mail (2.2.19) lib/mail/field.rb:123:in `method_missing'
mail (2.2.19) lib/mail/header.rb:190:in `encoded'
mail (2.2.19) lib/mail/header.rb:189:in `each'
mail (2.2.19) lib/mail/header.rb:189:in `encoded'
mail (2.2.19) lib/mail/message.rb:1708:in `encoded'
actionmailer (3.0.10) lib/action_mailer/base.rb:445:in `set_payload_for_mail'
actionmailer (3.0.10) lib/action_mailer/base.rb:425:in `deliver_mail'
activesupport (3.0.10) lib/active_support/notifications.rb:52:in `instrument'
activesupport (3.0.10) lib/active_support/notifications/instrumenter.rb:21:in `instrument'
activesupport (3.0.10) lib/active_support/notifications.rb:52:in `instrument'
actionmailer (3.0.10) lib/action_mailer/base.rb:424:in `deliver_mail'
mail (2.2.19) lib/mail/message.rb:230:in `deliver'
I had the same error, when trying to test my devise confirmation emails. Weird thing was, running the test isolated did not throw this exception. Running the whole stack did. After doing a binary search, i found, that one of my specs used REXML to parse some content.
require 'spec_helper'
require 'rexml/document'
include REXML
doc = Document.new(response.body)
I dont't know, why i included REXML, presumably, because i wanted to save the REXML:: in front of Document. But changing the code to this fixed the problem:
require 'spec_helper'
require 'rexml/document'
doc = REXML::Document.new(response.body)
if you happen to use code like this somewhere, this may fix this encode! issue with ruby 1.8.7
I found the issue to be with the mailer gem, changing to 2.2.13 fixed it for me.