to_xml always throws error - ruby-on-rails

I'm on Rails 3.1
I've pasted an example below, but Calling to_xml on any model throws this error. I've tried everything but I'm it's the sort of thing someone would have seen before. Does it ring any bells for anyone?
1.8.7 :004 > Person.first.to_xml
Person Load (2.0ms) SELECT `people`.* FROM `people` LIMIT 1
ArgumentError: wrong number of arguments (1 for 0)
from /home/khughes/.rvm/gems/ree-1.8.7-2012.02#rails31/gems/builder-3.0.0/lib/builder/xmlbase.rb:135:in `to_xs'
from /home/khughes/.rvm/gems/ree-1.8.7-2012.02#rails31/gems/builder-3.0.0/lib/builder/xmlbase.rb:135:in `_escape'
from /home/khughes/.rvm/gems/ree-1.8.7-2012.02#rails31/gems/builder-3.0.0/lib/builder/xmlbase.rb:140:in `_escape_quote'
from /home/khughes/.rvm/gems/ree-1.8.7-2012.02#rails31/gems/builder-3.0.0/lib/builder/xmlmarkup.rb:320:in `_attr_value'
from /home/khughes/.rvm/gems/ree-1.8.7-2012.02#rails31/gems/builder-3.0.0/lib/builder/xmlmarkup.rb:308:in `_insert_attributes'
from /home/khughes/.rvm/gems/ree-1.8.7-2012.02#rails31/gems/builder-3.0.0/lib/builder/xmlmarkup.rb:306:in `each'
from /home/khughes/.rvm/gems/ree-1.8.7-2012.02#rails31/gems/builder-3.0.0/lib/builder/xmlmarkup.rb:306:in `_insert_attributes'
from /home/khughes/.rvm/gems/ree-1.8.7-2012.02#rails31/gems/builder-3.0.0/lib/builder/xmlmarkup.rb:284:in `_special'
from /home/khughes/.rvm/gems/ree-1.8.7-2012.02#rails31/gems/builder-3.0.0/lib/builder/xmlmarkup.rb:250:in `instruct!'
from /home/khughes/.rvm/gems/ree-1.8.7-2012.02#rails31/gems/activemodel-3.1.1/lib/active_model/serializers/xml.rb:93:in `serialize'
from /home/khughes/.rvm/gems/ree-1.8.7-2012.02#rails31/gems/activerecord-3.1.1/lib/active_record/serializers/xml_serializer.rb:175:in `to_xml'
from (irb):4

had the same issue some time ago, do you have hpricot gem bundled into the project? if so, try to remove it from the Gemfile, run bundle and check if to_xml works
there's a solution that worked for me:
https://github.com/hpricot/hpricot/issues/53 ( see smeevil's post )

Related

Rails 5: Error when removed quiet_assets_path from development.rb

I have been trying to upgrade my app from Rails 4 to Rails 5. In my Rails 4 version I have quiet_assets_path set but in Rails 5 it is not required. But when I removed that tried to start the server I am getting the following error,
> ruby-2.2.2/gems/rack-mini-profiler-0.10.2/lib/mini_profiler_rails/railtie.rb:93:in
> `>': comparison of Fixnum with nil failed (ArgumentError) from
> /Users/Admin/.rvm/gems/ruby-2.2.2/gems/rack-mini-profiler-0.10.2/lib/mini_profiler_rails/railtie.rb:93:in
> `block in <class:Railtie>'
Can someone help me with this?
Edit:
Following is my rack_profiler.rb,
if Rails.env.development? || Rails.env.production?
require 'rack-mini-profiler'
# initialization is skipped so trigger it
Rack::MiniProfilerRails.initialize!(Rails.application)
Rack::MiniProfiler.config.skip_schema_queries = true
Rack::MiniProfiler.config.skip_paths += %w(/admin/sidekiq)
Rails.application.middleware.delete(Rack::MiniProfiler)
Rails.application.middleware.insert_after(Rack::Deflater, Rack::MiniProfiler)
end
When I comment the delete line then server is starting but if the line uncommented then the server breaks.
thanks for the update. First of all, do you use Rack::Deflater middleware in development environment too?
I think this issue might help you. It basically says that in Rails all delete middleware operations are issued at the end. You can use the swap method as described in the above issue.
If you search the repo issues for "Deflater" you'll find a lot of results, but I believe the above contains your fix.

"no implicit conversion of nil into String"in the Search Module of Redmine

On the redmine of my company, there is this bug where I get an internal error if I want to search into a project.
Here is the log corresponding to the error:
Processing by SearchController#index as HTML
Parameters: {"utf8"=>"✓", "issues"=>"1", "q"=>"test", "id"=>"sprint"}
Current user: me (id=60)
Completed 500 Internal Server Error in 85.0ms
TypeError (no implicit conversion of nil into String):
lib/plugins/acts_as_searchable/lib/acts_as_searchable.rb:126:in `search'
app/controllers/search_controller.rb:74:in `block in index'
app/controllers/search_controller.rb:73:in `each'
app/controllers/search_controller.rb:73:in `index'
The lines corresponding to the error in the controller are :
if !#tokens.empty?
# no more than 5 tokens to search for
#tokens.slice! 5..-1 if #tokens.size > 5
#results = []
#results_by_type = Hash.new {|h,k| h[k] = 0}
limit = 10
#scope.each do |s|
r, c = s.singularize.camelcase.constantize.search(#tokens, projects_to_search,
:all_words => #all_words,
:titles_only => #titles_only,
:limit => (limit+1),
:offset => offset,
:before => params[:previous].nil?)
#results += r
Here is my config :
Environment:
Redmine version 2.6.9.stable
Ruby version 2.3.0-p0 (2015-12-25) [x86_64-linux]
Rails version 3.2.22
Environment production
Database adapter PostgreSQL
SCM:
Git 1.9.1
Filesystem
Redmine plugins:
no plugin installed
What is interesting is that when I search only one letter, i'm redirected on the search page, but I don't have an internal error.
I'm very new to Redmine developpement and to Ruby, I was just assigned to try to fix this bug. Do any of you have an idea of how to fix it ?
Thanks.
I had the same issue, I was able to fix it by downgrading my ruby & rails version, a working set is :
Rails 3.2.19
Ruby 2.1.4p265
It's look like it's due to a braking change in ruby-2.3.0.
It's really odd. We are using 'Redmine' -2.0.3.1 and we do not have that kind of behaviour.
It seems that "someone" messed up the form linked to the search input. Try to follow that data from when you press enter until it answer you with the 500 error code.
If you can , change the environment to development, this way it will show you more detailed errors.
But I can't help you much more , you didn't provide enough info about the problem.

Activesupport / Multi json: "Did not recognize your adapter specification"

I have a Ruby 1.9.3 / Rails 3.1 project with the following in the gemfile:
gem 'rails', '3.1.12'
gem 'json'
gem 'multi_json', '1.7.7'
That version of rails sets activesupport to 3.1.12 as well. I'm not sure what the exact cause of the problem is, but when running bundle exec rake test, I got the error:
/home/user/.gem/ruby/1.9.3/gems/multi_json-1.7.7/lib/multi_json.rb:121:in 'rescue in load_adapter': Did not recognize your adapter specification. (ArgumentError)
...
(more stack trace, including activesupport methods)
Fortunately I found a solution! See below.
Edit: My original answer is outdated and incorrect; read it if you please, but please read the updated information at the bottom.
After viewing a ton of other questions such as these ones:
OmniAuth Login With Twitter - "Did not recognize your adapter specification." Error
Capistrano deploy: "Did not recognize your adapter specification" during assets:precompile
https://github.com/intridea/multi_json/issues/132
I hadn't found a solution, so I dove into the library and determined that load_adapter was receiving the parameter "JSONGem". The alias was failing, and the method attempted to load
/home/user/.gem/ruby/1.9.3/gems/multi_json-1.7.7/lib/multi_json/adapters/JSONGem.rb
This file doesn't exist, but .../json_gem.rb does exist! So I modified load adapter as follows:
def load_adapter(new_adapter)
# puts "new_adapter: #{new_adapter}" # Debugging
# puts "new_adapater.class: #{new_adapter.class}" # Debugging
case new_adapter
when String, Symbol
new_adapter = ALIASES.fetch(new_adapter.to_s, new_adapter)
new_adapter = "json_gem" if new_adapter =~ /^jsongem$/i # I added this line
# puts "final adapter: #{new_adapter}" # debugging
require "multi_json/adapters/#{new_adapter}"
klass_name = new_adapter.to_s.split('_').map(&:capitalize) * ''
MultiJson::Adapters.const_get(klass_name)
when NilClass, FalseClass
load_adapter default_adapter
when Class, Module
new_adapter
else
raise NameError
end
rescue NameError, ::LoadError
raise ArgumentError, 'Did not recognize your adapter specification.'
end
This fixed the problem for me. It's probably not an optimal solution (ideally I would understand WHY the ALIASES.fetch failed, if that is indeed what happened, and fix that), but if your problem is similar then hopefully this quick fix can help.
Update
It's not viable for deployability reasons to modify someone else's gem. Fortunately I found the root cause of the problem. In project_root/config/initializers/security_patches.rb, we had the line
ActiveSupport::JSON.backend = "JSONGem"
This was the recommended fix to a security bug in older versions of rails. Now that we are on a newer version of rails (i.e, > 3.0), we can simply replace "JSONGem" with "json_gem" (which is what my original modification was doing, in a roundabout way) and not worry about the security issue.

Rails. wrong number of arguments error when trying to set beginning_of_week

I followed this Railscast: http://railscasts.com/episodes/213-calendars-revised
It seems that not a lot of people are getting an error but I get ArgumentError: wrong number of arguments (1 for 0) for this call:
first = date.beginning_of_month.beginning_of_week(START_DAY)
Even, if I try it in the console it also gives me the same error.
Date.today.beginning_of_month.beginning_of_week(start_day = :sunday)
Date.today.beginning_of_month.beginning_of_week(start_day = 'sunday')
Date.today.beginning_of_month.beginning_of_week('sunday')
Date.today.beginning_of_month.beginning_of_week(:sunday)
I already Googled it and looked in the docs and it seems it should just work. I even tried require 'active_support/all but it always returns false.
How can I set the beginning of week as Sunday?
I cant access the screencast. But when i run Rails in Console mode (not IRB):
rails c (Ruby v1.9.3p194)
Loading development environment (Rails 3.2.8)
1.9.3p194 :001 > Date.today.beginning_of_month.beginning_of_week(start_day = :sunday)
=> Sun, 29 Jul 2012
1.9.3p194 :002 >
Maybe its your Ruby or Rails version, i'm running: rails (3.2.8)?
The parameter (what day the week starts) seems to be added since 3.2.1:
http://apidock.com/rails/v3.2.1/Date/beginning_of_week

number_with_precision return Integer

I have a very weird problem with number_with_precision() and number_to_currency().
In my application, they both raise an comparison of String with 0 failed if i do not set :precision
But when i try the very same functions in irb, everything is fine :
1.9.3p0 :058 > helper.number_with_precision(12)
=> "12.000"
1.9.3p0 :059 > helper.number_to_currency(12)
=> "12.00 €"
I looked in to my Gemfile, guessing it could be coming from one of my Gem, but i did not find anything.
I have the strange sensation that something is overriding number_with_delimiter(), causing this error, but i can't find out what.
FYI, i use Rails 3.2.1 and ruby 1.9.1, and here is my Gemfile: https://gist.github.com/2847099
Thank you per advance.

Resources