Comments (17)
It might be because I do have a Collection model so I use the @collections var. pity I can't change it as a i need { '"collections" : [] } result
from rabl-rails.
Looks like I worked it out by not using vars @collection and @collections in the controller. It works already a few hours but it certainly sucks. I'd love to have it fixedm but onsuch a schedule so can't ebough time to investigate... Worst of all, it means that we can get same problems when using methods/vars in our models/controller, like @child, bode, @Attribute?
from rabl-rails.
What's inside your 'api/commons/collection' ? Because the problem seems not to be the ivar name @collections
, but that you are trying to call a method #collection
on your Collection
model...
from rabl-rails.
Actually I don't have Collection#collection anywhere. Though I have it in other models, say Item#collection. Anyway:
api/commons/collection:
attributes :id, :name
node(:cover_url) { |c|
c.cover(:medium)
}
I've got a strange workaround that works for now: i do not use @collection && @collections in neither in the conroller nor in views, i have rewritten them to:
child(:@cc => :collections) {
extends 'api/commons/collection'
}
and collections/show (that sometimes gave same error) as:
child(:@c => :collection) do
extends 'api/commons/collection'
child(:@items) {
extends 'api/commons/item'
}
end
and it still works. Though its ugly :(
from rabl-rails.
I wrote a test with a Collection
model, and it works fine. Could you come up with a small example project that reproduces the bug ?
from rabl-rails.
This version did not work (actually, it works some time, then fails, after some point it returns above mentioned error. It could, though^ serve hundreds request just fine first, so it was not easy to track and would not be easy for you to reproduce:
class Api::CollectionsController < Api::ApplicationController
before_filter :load_collection, :except => [:index]
def index
@collection = Collection.all
# rabl: collection :@collection
end
def show
# rabl: object :@collection
end
private
def load_collection
@collection = Collection.find(params[:id])
@Items = @collection.items.order('id desc').limit(300)
end
end
Th workaround that works:
class Api::CollectionsController < Api::ApplicationController
before_filter :load_collection, :except => [:index]
def index
@cc = Collection.all
# rabl child(:@cc => :collections) {
end
def show
# Rabl: child(:@c => :collection) do
end
private
def load_collection
@c = Collection.find(params[:id])
@Items = @c.items.order('id desc').limit(300)
end
end
Sorry I just have no time now to extract the sample project, would do it after release that is less than two weeks ahead. But for sure it got fixed by this small change. It is not because of the Collection model as I though, this fix yields that only @collection/@collections vars/attributes in the controller context caused the problem. And certainly it hash a random natude: some requests are served ke, some got broken. It looks like that rabl
collection :@collection
sometimes return my @collection attribute from the controller's context, and sometimes a valid rabl object whatever it is ;) Ot something very close, as the key was "collection :@collection" fix.
23.10.2012, â 14:04, Christopher Cocchi-Perrier [email protected] íàïèñàë(à):
I wrote a test with a Collection model, and it works fine. Could you come up with a small example project that reproduces the bug ?
—
Reply to this email directly or view it on GitHub.
from rabl-rails.
Worst of all I've got another clash like this: Controller var @item somehow sometimes hide template api/commons/item. After 30m of trying to find the reason os some strange error about 'missing item attribute' - and I never used one - the problem dissapears on the exactly same code :(
from rabl-rails.
Are you using the cache_templates
option or a multithreaded application?
from rabl-rails.
no. I use nginx+passenger in the single threaded mode. rails 3.2.8, ruby 1.9.3
Are you using the cache_templates option or a multithreaded application?
—
Reply to this email directly or view it on GitHub.
from rabl-rails.
The log of the exception:
Started GET "/api/items/10" for 128.72.171.138 at 2012-10-31 04:09:16 +0000
Processing by Api::ItemsController#show as JSON
Parameters: {"id"=>"10", "item"=>{}}
12/10/31 04:09:16 : Api::ItemsController : Authtoken is taken from headers
Rendered api/items/show.rabl (9.9ms)
Failure: undefined method item' for #<Item:0x00000005b1fe68> Class: NoMethodError /var/www-data/mydreamboardapp.com/shared/bundle/ruby/1.9.1/gems/activemodel-3.2.8/lib/active_model/attribute_methods.rb:407:in
method_missing'
/var/www-data/mydreamboardapp.com/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.8/lib/active_record/attribute_methods.rb:149:in method_missing' /var/www-data/mydreamboardapp.com/shared/bundle/ruby/1.9.1/gems/rabl-rails-0.2.2/lib/rabl-rails/renderers/base.rb:56:in
block in render_resource'
/var/www-data/mydreamboardapp.com/shared/bundle/ruby/1.9.1/gems/rabl-rails-0.2.2/lib/rabl-rails/renderers/base.rb:51:in each' /var/www-data/mydreamboardapp.com/shared/bundle/ruby/1.9.1/gems/rabl-rails-0.2.2/lib/rabl-rails/renderers/base.rb:51:in
inject'
/var/www-data/mydreamboardapp.com/shared/bundle/ruby/1.9.1/gems/rabl-rails-0.2.2/lib/rabl-rails/renderers/base.rb:51:in render_resource' /var/www-data/mydreamboardapp.com/shared/bundle/ruby/1.9.1/gems/rabl-rails-0.2.2/lib/rabl-rails/renderers/base.rb:31:in
render'
/var/www-data/mydreamboardapp.com/shared/bundle/ruby/1.9.1/gems/rabl-rails-0.2.2/lib/rabl-rails/library.rb:18:in get_rendered_template' /media/data1/www-data/mydreamboardapp.com/releases/20121030163245/app/views/api/items/show.rabl:2:in
_app_views_api_items_show_rabl__1357555209293645053_33622280'
/var/www-data/mydreamboardapp.com/shared/bundle/ruby/1.9.1/gems/actionpack-3.2.8/lib/action_view/template.rb:145:in block in render' /var/www-data/mydreamboardapp.com/shared/bundle/ruby/1.9.1/gems/activesupport-3.2.8/lib/active_support/notifications.rb:125:in
instrument'
/var/www-data/mydreamboardapp.com/shared/bundle/ruby/1.9.1/gems/actionpack-3.2.8/lib/action_view/template.rb:143:in render' /var/www-data/mydreamboardapp.com/shared/bundle/ruby/1.9.1/gems/actionpack-3.2.8/lib/action_view/renderer/template_renderer.rb:47:in
block (2 levels) in render_template'
/var/www-data/mydreamboardapp.com/shared/bundle/ruby/1.9.1/gems/actionpack-3.2.8/lib/action_view/renderer/abstract_renderer.rb:38:in block in instrument' /var/www-data/mydreamboardapp.com/shared/bundle/ruby/1.9.1/gems/activesupport-3.2.8/lib/active_support/notifications.rb:123:in
block in instrument'
/var/www-data/mydreamboardapp.com/shared/bundle/ruby/1.9.1/gems/activesupport-3.2.8/lib/active_support/notifications/instrumenter.rb:20:in instrument' /var/www-data/mydreamboardapp.com/shared/bundle/ruby/1.9.1/gems/activesupport-3.2.8/lib/active_support/notifications.rb:123:in
instrument'
/var/www-data/mydreamboardapp.com/shared/bundle/ruby/1.9.1/gems/actionpack-3.2.8/lib/action_view/renderer/abstract_renderer.rb:38:in instrument' /var/www-data/mydreamboardapp.com/shared/bundle/ruby/1.9.1/gems/actionpack-3.2.8/lib/action_view/renderer/template_renderer.rb:46:in
block in render_template'
/var/www-data/mydreamboardapp.com/shared/bundle/ruby/1.9.1/gems/actionpack-3.2.8/lib/action_view/renderer/template_renderer.rb:54:in render_with_layout' /var/www-data/mydreamboardapp.com/shared/bundle/ruby/1.9.1/gems/actionpack-3.2.8/lib/action_view/renderer/template_renderer.rb:45:in
render_template'
/var/www-data/mydreamboardapp.com/shared/bundle/ruby/1.9.1/gems/actionpack-3.2.8/lib/action_view/renderer/template_renderer.rb:18:in render' /var/www-data/mydreamboardapp.com/shared/bundle/ruby/1.9.1/gems/actionpack-3.2.8/lib/action_view/renderer/renderer.rb:36:in
render_template'
/var/www-data/mydreamboardapp.com/shared/bundle/ruby/1.9.1/gems/actionpack-3.2.8/lib/action_view/renderer/renderer.rb:17:in render' /var/www-data/mydreamboardapp.com/shared/bundle/ruby/1.9.1/gems/actionpack-3.2.8/lib/abstract_controller/rendering.rb:110:in
_render_template'
/var/www-data/mydreamboardapp.com/shared/bundle/ruby/1.9.1/gems/actionpack-3.2.8/lib/action_controller/metal/streaming.rb:225:in _render_template' /var/www-data/mydreamboardapp.com/shared/bundle/ruby/1.9.1/gems/actionpack-3.2.8/lib/abstract_controller/rendering.rb:103:in
render_to_body'
/var/www-data/mydreamboardapp.com/shared/bundle/ruby/1.9.1/gems/actionpack-3.2.8/lib/action_controller/metal/renderers.rb:28:in render_to_body' /var/www-data/mydreamboardapp.com/shared/bundle/ruby/1.9.1/gems/actionpack-3.2.8/lib/action_controller/metal/compatibility.rb:50:in
render_to_body'
/var/www-data/mydreamboardapp.com/shared/bundle/ruby/1.9.1/gems/actionpack-3.2.8/lib/abstract_controller/rendering.rb:88:in render' /var/www-data/mydreamboardapp.com/shared/bundle/ruby/1.9.1/gems/actionpack-3.2.8/lib/action_controller/metal/rendering.rb:16:in
render'
Completed 500 Internal Server Error in 90ms (Views: 0.4ms | ActiveRecord: 0.7ms)
I never use 'item' as an attribute. I use it as object. In the controller it is set like:
def load_item
@item = Item.find params[:id] || params[:item_id]
end
In the view:
object :@item
extends 'api/commons/item'
child(:@marks) do
extends 'api/commons/mark'
end
from rabl-rails.
Worst of all, it appears after some considerable radnom time and dissapear with application restart. For some time. then it appears again. I have a week to production - probably would temporaily switch to slow rable until this thing will be fixed. thanks in advance. If the problem persists - that means, not in you gem, I'll close the issue.
from rabl-rails.
I've used this gem in production for months now and I never ran in this problem. The randomness of this make me think of 2 issues : multithreading or caching problems. Are you sure you've tried with the cache_templates
options set to false
?
from rabl-rails.
Actually, I didn't touch settings at all. I'll add it right now and uncomment cache_templates and see what will happen. Actually, it might be interference of rails internals and ruby version. Maybe even some bug in ruby. Well, lets see whether default settings will help it I'll set 'em by hand.
Might it be because I had no
config/initializers/rabl_rails.rb
RablRails.configure do |config|
These are the default
config.cache_templates = true
config.include_json_root = true
config.json_engine = :oj
config.xml_engine = 'LibXML'
config.use_custom_responder = false
# config.default_responder_template = 'show'
end
block at all?
Thanks again!
31.10.2012, â 12:27, Christopher Cocchi-Perrier [email protected] íàïèñàë(à):
I used this gem in production for months now and I never ran in this problem. The randomness of this make me think of 2 issues : multithreading or caching problems. Are you sure you set the cache_templates options to true ?
—
Reply to this email directly or view it on GitHub.
from rabl-rails.
Try to set cache_templates to false.
When it is enable, it will cache the compiled source according to the path of the template. For example if you render views/items/show
, it will used items/show
as cache key so next time you render it or use extends "items/show"
, it will use the compiled source directly.
Maybe there are cache key collisions with your setup
from rabl-rails.
Any news concerning this issue?
from rabl-rails.
Still the same. Works few hours then something happens and it fails on every request since then. Bad luck :(
Sergey.
06.11.2012, â 2:42, Christopher Cocchi-Perrier [email protected] íàïèñàë(à):
Any news concerning this issue?
—
Reply to this email directly or view it on GitHub.
from rabl-rails.
I added a test with collection keywords to ensure there is no problem.
I also tried to reproduce your problem but without success. I'm closing this issue for now, since others website running with rabl-rails aren't encountering it.
I would gladly reopen it if you can reproduce the issue in a basic rails app. Thanks for your feedback anyway ❤️
from rabl-rails.
Related Issues (20)
- rabl-rails renders JSON instead of XML in some cases HOT 3
- iso8601 dates break on 0.4.0 HOT 1
- New way of format retrieving caused problems with gon gem HOT 4
- wiki page 'Render object directly' references to non existing class HOT 1
- Rails 4.2 HOT 4
- Object 'nil' with extends HOT 1
- fields filter?
- Conditional attributes not working HOT 1
- use_custom_responder = true doesn't work on RoR 4.2 HOT 1
- Not being able to use a cache key in rabl generated by controller. HOT 2
- Object root not included in 0.4.2, but was in 0.4.1 HOT 7
- Response contains ":" in rails 5 HOT 1
- rabl-rails for rails-5-api? HOT 5
- undefined method for nil:NilClass on Rails 5.0.1 HOT 2
- Upgrading to 0.5.0 from 0.4.3 encountering error "undefined method `render' for RablRails:Module" HOT 6
- Results caching with object set to false
- Need to remove .json from url
- `rendered_format` is removed in Rails 6.1 HOT 4
- single arity deprecation warning for Rails 6.1 HOT 2
- Rails 6 warning: autoloading ActionController::Base during initialization HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rabl-rails.