Rails Rabl gem not showing line numbers - ruby-on-rails-3

Whenever the rendering in rabl templates fails, it just shows the error. It does not show the line numbers. Has anyone faced this issue yet?
Example trace:
Rendered campaigns/show.json.rabl (1377.9ms)
undefined method `[]' for nil:NilClass
(eval):21:in `block (2 levels) in render'
/Users/pkhadloya/.rbenv/versions/1.9.3-p392/gemsets/myapp/gems/rabl-0.8.5/lib/rabl/builder.rb:87:in `call'
/Users/pkhadloya/.rbenv/versions/1.9.3-p392/gemsets/myapp/gems/rabl-0.8.5/lib/rabl/builder.rb:87:in `node'

Got this helpful link: http://davidsommers.com/2012/07/28/use-the-debugger-not-puts.html
It shows how to debug in rabl. But line numbers would have been more beneficial.

Related

undefined method `featured' for Post

I try to add a full-text search in my app. With gem 'sunspot_rails', '~> 2.3' and gem 'sunspot_solr', '~> 2.3' for my app. When i try save something in mysql db like:
#post = Post.new
#post.title = "Theorema"
#post.save
It gives me ROLLBACK and:
NoMethodError (undefined method `featured' for #<Post:0x00007f018ab005d0>):
I am beginer and will be grateful for any help!
Welcome to SO Oleg.
Have you got an attribute featured in your Post model?
There is one on the github page of the gem you used.
Maybe you copied it by mistake. Either remove that if you do not need it or add it to posts and migrate.
Can not really tell without seeing your Post model.

Including/importing HAML files using grunt-contrib-haml and Yeoman

I am currently using Yeoman with HAML (utilising grunt-contrib-haml) and would like to include HAML files to make things more DRY.
I am not that familiar with HAML, so after reading online it appears best to use =render, like so:
=render(partial="shared/ga")
however I am receiving the message that HAML lacks a native render() function:
Warning: Exception on line 75: undefined method `render' for #<Object:0x00000003474a98>
Is there a simple way to include HAML files from inside another HAML file, which will work with Yeoman/grunt-contrib-haml? and/or extending an existing HAML template to make things more DRY?
I had the same issue. I found that the simplest approach to this issue is to use js to import the files instead of the haml method. I'm using Angular.js so I can use it's imports and skip HAML's.
In the HAML template you write something like this (for Angular):
%div#publish{ng-include: 'views.someview', ng-controller: 'SomeCtrl'}
Works like a charm.

undefined method 'signed_in?' in cucumber BDD when using "assert ! controller.signed_in"

I am working on cucumber BDD on rails-3 application.
When I use "assert ! controller.signed_in?" in step_definition
And When I run "cucumber"
Then I got this error "undefined method 'signed_in?' for nil:NilClass (NoMethodError)"
Why is it not going into controller-helper (signed_in? is defined in sessions_helper)?
When I tried by "assert ! SessionsController.signed_in?"
Error : undefined method `signed_in?' for SessionsController:Class (NoMethodError)
And When "assert ! SessionsHelpers.signed_in?"
Error : undefined method `signed_in?' for SessionsHelper:Module (NoMethodError)
In my Sessions_helper:
def signed_in?
!current_user.nil?
end
I also experienced this issue, and solved it by adding World(SessionsHelper) to the bottom of the Cucumber steps file (there's probably a better place to put it).
On a side note, you'll probably encounter other issues relating to cookies and sessions as it appears Cucumber does not support these between requests. So for example, you won't be able to test signed_in? after performing a redirect/submitting to the login form.

How to write RefineryCMS controller tests without RoutingError

An Rspec test like this (actually taken from RefineryCMS' own test suite)
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
module Refinery
describe FastController do
it "should render the wymiframe template" do
get :wymiframe
response.should be_success
end
end
end
Results in the following error:
Failure/Error: get :wymiframe
ActionController::RoutingError:
No route matches {:controller=>"refinery/fast", :action=>"wymiframe"}
# ./spec/controllers/fast_controller_spec.rb:6:in `block (2 levels) in <module:Refinery>'
In this case, I'm using refinery 2.0.8 with Rspec 2.11, and the relevant section after running rake routes looks like:
wymiframe GET /wymiframe(/:id)(.:format) refinery/fast#wymiframe
I have tried a few other controller Rspecs which also fail with routing errors. I am of course trying to write tests for my own extra methods I am adding to vanilla Refinery controllers, but just thought I'd see if I could get a controller test working for a totally fresh refinery install.
This must be a simple mistake! Any suggestions?
I stumbled upon this by accident. Instead of:
get :wymiframe
I needed to use:
get :wymiframe, { use_route: :any_old_thing }
I don't know why this worked - especially since for "any_old_thing", I really used nothing meaninful or connected tomy project at all. But, it seems to have worked, and now I can test my controllers.

Dragonfly adding images to store before Model.save

The Dragonfly doc implies that nothing is written to the datastore until the model is saved:
When the model is saved, a before_save callback persists the data to
the App's configured datastore
Using Rails and Dragonfly 0.9.12, I have a model Article with image_accessor :image, and my store is S3.
The following is sufficient to store an image in S3:
Browser uploads image or provides image_url.
New model instance: #article = Article.new(params[:article]))
That's it. If I add processing via after_assign :resize_image, then the processed version is stored.
Is this behavior intentional? It's causing stray images to be uploaded to S3. I don't always save #article to db, but I still need Dragonfly to resize the image. (If you're curious, I'm sending it back to the browser for a preview as embedded data using Base64.encode64(#article.image.data).)
To investigate, I disconnected my internet to interrupt the store operation. This is the relevant portion of the trace:
dragonfly (0.9.12) lib/dragonfly/active_model_extensions/attachment.rb:179:in `store_job!'
dragonfly (0.9.12) lib/dragonfly/active_model_extensions/attachment.rb:118:in `retain!'
dragonfly (0.9.12) lib/dragonfly/active_model_extensions/class_methods.rb:63:in `block (3 levels) in register_dragonfly_app'
mongoid (3.0.3) lib/mongoid/attributes/processing.rb:102:in `process_attribute'
mongoid (3.0.3) lib/mongoid/attributes/processing.rb:27:in `block in process_attributes'
mongoid (3.0.3) lib/mongoid/attributes/processing.rb:25:in `each_pair'
mongoid (3.0.3) lib/mongoid/attributes/processing.rb:25:in `process_attributes'
mongoid (3.0.3) lib/mongoid/document.rb:147:in `block in initialize'
mongoid (3.0.3) lib/mongoid/threaded/lifecycle.rb:84:in `_building'
mongoid (3.0.3) lib/mongoid/document.rb:142:in `initialize'
How can I get around this? Thanks.
This is caused by using <%= f.hidden_field :retained_image %>.