Comments (15)
Can you share the code that is causing the issue?
from tilt-jbuilder.
Sure.
In Sinatra (working under Rails as middleware /app/api/v1/routes/users.rb
jbuilder :profile_detailed , :format => 'json'
View:
Jbuilder.encode do |json|
json.(@user, :id, :job_position, :avatar_url, :startup_value, :ufo_name, :name, :email, :email_verified, :last_verified_email, :annual_investment, :annual_investment_currency, :primary_role, :properties, :images)
json.partial! 'account', collection: @accounts, as: :account
end
from tilt-jbuilder.
I found the source of the error. sinatra-contrib gem is messing it up.
from tilt-jbuilder.
Hm, ok. Thanks for looking into this.
Do you know what is causing/where in the sinatra-contrib gem this issues is popping up?
from tilt-jbuilder.
I didn't go into details out there, but it was JSON helper. We were not using is so I forked it and commented it out. https://github.com/software-project/sinatra-contrib
from tilt-jbuilder.
Hi @anthonator,
My application has the same issue. Tracing through the code, I believe I found the cause. Unfortunately, I'm not good enough to provide a fix. My finding is below.
My application uses sinatra/respond_with
, with require
s sinatra/json
. In sinatra/json
, a method json
is defined (please click link for code).
In jbuilder
gem, an alias method is used to start the rendering. jbuilder
aliases method_missing
to the rendering method set!
(code)
Since sinatra/json
already declared the method json
, when the sinatra-view is rendered, it never hit the above method_missing
(and therefore also never hit the set!
method). Instead, sinatra/json
's json
method is used, causing this error.
Through the trace, the closest I can get to, in tilt/jbuilder
, is this
When you have time, can you please take a look? Thank you.
from tilt-jbuilder.
@manchunlam Thanks for the detailed response.
Could you share the code that's giving you issues?
from tilt-jbuilder.
If you're doing something similar to:
Jbuilder.encode do |json|
...snip...
end
could you try
Jbuilder.encode do |jbuilder|
...snip...
end
Note that |jbuilder|
is arbitrary. You can change out jbuilder
for anything other than json. It may just be a keyword conflict.
from tilt-jbuilder.
The problem still persists.
The code causing the error:
gem "sinatra", :require => "sinatra/base"
gem "sinatra-contrib"
gem 'tilt-jbuilder', :require => "sinatra/jbuilder"
app.get '/users' do
jbuilder :users
end
In views/users.jbuilder
Jbuilder.encode do |bla|
bla.id 'bla'
end
from tilt-jbuilder.
I'm unfamiliar with sinatra/contrib
so could you fill me in on why you need both tilt-jbuilder
and sinatra/json
in your project? @software-project had to literally comment out sinatra/json
. It seems to be a better scenario to just not include the sinatra/json
module. sinatra/contrib
is modular so you can only load in what you need.
from tilt-jbuilder.
Also, as a side note, I've run my specs using sinatra/contrib
but without sinatra/json
and they passed. Once I added in sinatra/json
I began to see issues.
from tilt-jbuilder.
I pushed support for sinatra/json
with accompanying tests. Could someone please test against master?
from tilt-jbuilder.
👍 master has fixed the issue against sinatra/contrib
for me
from tilt-jbuilder.
Any chance you could release a new version to rubygems soon? ❤️
from tilt-jbuilder.
And done.
from tilt-jbuilder.
Related Issues (8)
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 tilt-jbuilder.