undefined method `parent' for nil:NilClass - ruby-on-rails

I'm getting this strange error using Rails 3.0.2.
ActionView::Template::Error (undefined method `parent' for nil:NilClass):
app/controllers/channels_controller.rb:19:in `index'
This is the controller, and line 19 is the respond_with(#channels) block.
Where do I start to search for errors?
class ChannelsController < ApplicationController
before_filter :set_default_client
respond_to :html, :xml
def index
if params[:cache_set]
#channels = Channel.active.find_all_by_id(params[:cache_set])
else
#channels = Channel.active.find_all_by_id(cookies[:channels].split(','))
end
respond_with(#channels)
end
end
This is the full error:
ActionView::Template::Error (undefined method `parent' for nil:NilClass):
app/controllers/channels_controller.rb:19:in `index'
Rendered /Users/linus/.rvm/gems/ruby-1.8.7-p330/gems/actionpack-3.0.2/lib/action_dispatch/middleware/templates/rescues/_trace.erb (1.3ms)
Rendered /Users/linus/.rvm/gems/ruby-1.8.7-p330/gems/actionpack-3.0.2/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (19.8ms)
Rendered /Users/linus/.rvm/gems/ruby-1.8.7-p330/gems/actionpack-3.0.2/lib/action_dispatch/middleware/templates/rescues/template_error.erb within rescues/layout (28.6ms)
I'm using Ruby 1.8.7 with Rails 3.0.2.
I've also, just in case, tried Rails 3.0.7 and 3.0.0.

Are you in any case using HAML?
I just bumped into this as well and my colleague (who is not on Stackoverflow yet) found out that it was due to multiline comments in the view template
-#
= helper_method_1
= helper_method_2

I solved the problem by changing HAML version from 3.1.x to 3.0.24.
My new Gemfile looks like this.
gem "rails", "3.0.2"
gem "haml", "3.0.24"
gem "compass", "0.10.6"

It looks like HAML-edge has fixed this problem.
I expect the next release of HAML after 3.1.1 to resolve this.

Related

Rails 5, Ckeditor and Paperclip error when loading and searching for images

I'm using rails 5 api and am trying to implement a ckeditor wysiwyg in a form using angularjs 1. I'm using rails 5.1.4, ckeditor 4.2 and paperclip 5.1.0.
I have followed the directions from here: https://github.com/galetahub/ckeditor for the gem implementation and have run the generator:
rails generate ckeditor:install --orm=active_record --backend=paperclip
When trying to "Browse Server" or upload an image to the server through the ckeditor I am performing the following Get request:
Started GET "/ckeditor/pictures?CKEditor=js-ckeditor&CKEditorFuncNum=1&langCode=en" for 172.23.0.1 at 2017-10-24 01:59:04 +0000
And I then get the following error:
ActionController::RoutingError (undefined method `layout' for Ckeditor::ApplicationController:Class):
ckeditor (4.2.4) app/controllers/ckeditor/application_controller.rb:2:in `<class:ApplicationController>'
ckeditor (4.2.4) app/controllers/ckeditor/application_controller.rb:1:in `<top (required)>'
This is the controller where the error is coming from: https://github.com/galetahub/ckeditor/blob/master/app/controllers/ckeditor/application_controller.rb
Edit: Turns out the rails 5 api does not include ActionView::Layouts out of the box, so I added this following to my ApplicationController:
include ::ActionView::Layouts
This took care of the undefined method 'layout'. However, now I have another error coming from the same ckeditor controller after the Get request has been passed to the index action. I am also using devise_token_auth and pundit for authorization and authentication.
Processing by Ckeditor::PicturesController#index as HTML
Parameters: {"CKEditor"=>"js-ckeditor", "CKEditorFuncNum"=>"1", "langCode"=>"en"}
Completed 500 Internal Server Error in 149ms (ActiveRecord: 0.0ms)
NoMethodError (undefined method `ckeditor_authorize!' for #<Ckeditor::PicturesController:0x007f5e7ac7dc30>):
this is the CKeditor Application Controller where you get the error, you should include this code to your question with link to the page
class Ckeditor::ApplicationController < Ckeditor.parent_controller.constantize
layout Ckeditor.controller_layout
before_action :find_asset, only: [:destroy]
before_action :ckeditor_authorize!
before_action :authorize_resource
protected
def respond_with_asset(asset)
asset_response = Ckeditor::AssetResponse.new(asset, request)
if asset.save
render asset_response.success(config.relative_url_root)
else
render asset_response.errors
end
end
end
I don't know why it is not working and I don't have any idea what Ckeditor.controller_layout is.. keep me updated with your progress

Pagination issue: `map' : undefined method 'existent'

I just installed the will_paginate, 3.0.7 and bootstrap-will_paginate, 0.0.10 gem and when i call the following to get my articles paginated
def index
#articles = Article.paginate(page: params[:page], per_page: 5)
end
I get the following error upon attempting to launch the localhost server
/Users/Jack/.rvm/gems/ruby-2.3.1#global/gems/activesupport-5.0.0.1/lib/active_support/i18n_railtie.rb:45:in `map': undefined method `existent' for #<String:0x007fd4a2bfa5d0> (NoMethodError)
Did you mean? extend
What's going wrong?
This was an issue with earlier version of will_paginate with Rails 5.
You need to update your will_paginate gem to use latest updated one which is:
gem 'will_paginate', '3.1.5'
This issue has been fixed with this merge:
https://github.com/mislav/will_paginate/pull/450

undefined method `name' for nil:NilClass with ruby 2.2.2

I've 2 classes with a has_and_belongs_to_many relation.
When I try to destroy an object I get:
> undefined method `name' for nil:NilClass error.
I'm using Ruby 2.2.2. The same code works fine with Ruby 2.1.2.
My controller code:
#cart = Cart.find(1)
#cart.temp_orders.find(4).destroy
My models:
class Cart < ActiveRecord::Base
has_many :temp_orders
end
class TempOrder < ActiveRecord::Base
belongs_to :cart
has_and_belongs_to_many :kids, join_table: :kid_temp_orders
end
class Kid < ActiveRecord::Base
has_and_belongs_to_many :temp_orders
end
Stack trace:
> NoMethodError (undefined method `name' for nil:NilClass): app/controllers/carts_controller.rb:50:in `destroy'
> Rendered /home/dell/.rvm/gems/ruby-2.2.1/gems/actionpack-4.1.1/lib/action_dispatch/middleware/templates/rescues/_source.erb (5.8ms)
> Rendered /home/dell/.rvm/gems/ruby-2.2.1/gems/actionpack-4.1.1/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (29.3ms)
> Rendered /home/dell/.rvm/gems/ruby-2.2.1/gems/actionpack-4.1.1/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb (10.7ms
> Rendered /home/dell/.rvm/gems/ruby-2.2.1/gems/actionpack-4.1.1/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (123.5ms
OP indeed can't post any other data for this error. I think OP doesn't deserve those down votes in this case.
This is an issue with ActiveRecord and Ruby 2.2
You can fix it by switching the ruby version from ruby-2.2.0 to ruby-2.1.2/ruby-2.1.3 or rails version from 4.0.0 to 4.1.2
Check this SO link
upgrading from:
ruby '2.3.0'
gem 'rails', '4.1.1'
to:
ruby '2.3.0'
gem 'rails', '4.1.16'
did the trick for me

ActionView::Template::Error (undefined method `force_encoding' for nil:NilClass):

I'm using Gems in 'vendor/bundler'. When I got Encoding error, I fixed it by adding a file named 'output_safty_encoding_patch.rb' in 'config/initializer':
output_safty_encoding_patch.rb
module ActiveSupport
class SafeBuffer < String
def concat(value)
if value.html_safe?
super(value.force_encoding('utf-8'))
else
super(ERB::Util.h(value.force_encoding('utf-8')))
end
end
alias << concat
end
end
Then I used gem 'devise' and tried to create a new post.
I got this error.
ActionView::Template::Error (undefined method `force_encoding' for nil:NilClass):
My logs:
Processing by PostsController#new as HTML
Rendered posts/_form.html.slim (30.2ms)
Rendered posts/new.html.erb within layouts/application (36.8ms)
Completed 500 Internal Server Error in 43ms
ActionView::Template::Error (undefined method `force_encoding' for nil:NilClass):
1: = form_for(#post) do |f|
2: -if #post.errors.any?
3: #error_explanation
4: h2= pluralize(#post.errors.count, "error")
config/initializers/output_safty_encoding_patch.rb:7:in `concat'
app/views/posts/_form.html.slim:1:in _app_views_posts__form_html_slim__2419859499811208315_70341230451880
app/views/posts/new.html.erb:4:in _app_views_posts_new_html_erb___3935161508588949089_70341230567660
You may want to reconsider the monkey-patch of ActiveSupport::Safebuffer (the file you've got in config/initializers/output_safty_encoding_patch.rb).
Altering behavior of a core class is bound to run into issues that are difficult to debug (like this one).
Maybe you could post a question about the problem that led you to the monkey-patch in the first place?

Undefined local variable or method `searchkick'

I'm trying to add Searchkick to my Rails application. I'm following the exact instructions on the Get started page but I keep getting the following error:
Started GET "/airports" for 10.0.2.2 at 2014-05-26 10:20:33 +0000
Processing by AirportsController#index as HTML
Completed 500 Internal Server Error in 26ms
NameError (undefined local variable or method `searchkick' for #<Class:0xb48f3ba8>):
app/models/airport.rb:2:in `<class:Airport>'
app/models/airport.rb:1:in `<top (required)>'
app/controllers/airports_controller.rb:3:in `index'
Rendered /home/vagrant/.rvm/gems/ruby-2.1.1#global/gems/actionpack-4.1.1/lib/action_dispatch/middleware/templates/rescues/_source.erb (0.5ms)
Rendered /home/vagrant/.rvm/gems/ruby-2.1.1#global/gems/actionpack-4.1.1/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (1.2ms)
Rendered /home/vagrant/.rvm/gems/ruby-2.1.1#global/gems/actionpack-4.1.1/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb (0.9ms)
Rendered /home/vagrant/.rvm/gems/ruby-2.1.1#global/gems/actionpack-4.1.1/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (19.8ms)
Here's what the Airport model looks like:
# ./app/models/airport.rb
class Airport < ActiveRecord::Base
searchkick
end
And this is what the Airport controller looks like:
# ./app/controllers/airports_controller/rb
class AirportsController < ApplicationController
def index
#airports = Airport.all
end
end
What's causing this?
Restart the server. The server has to be restarted after a change is made to the Gemfile.
Other things you can try if that doesn't work:
add gem 'searchkick' to the Gemfile
bundle install
Same here. I checked gem list, searchkick was there.
But I deleted searchkick in Gemfile and runned bundle install. Then add searchkick and bundle install again, it works well:)

Resources