Giter Site home page Giter Site logo

Comments (15)

anthonator avatar anthonator commented on July 17, 2024

Can you share the code that is causing the issue?

from tilt-jbuilder.

software-project avatar software-project commented on July 17, 2024

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.

software-project avatar software-project commented on July 17, 2024

I found the source of the error. sinatra-contrib gem is messing it up.

from tilt-jbuilder.

anthonator avatar anthonator commented on July 17, 2024

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.

software-project avatar software-project commented on July 17, 2024

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.

manchunlam avatar manchunlam commented on July 17, 2024

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 requires 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.

anthonator avatar anthonator commented on July 17, 2024

@manchunlam Thanks for the detailed response.

Could you share the code that's giving you issues?

from tilt-jbuilder.

anthonator avatar anthonator commented on July 17, 2024

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.

mmolchan-carecloud avatar mmolchan-carecloud commented on July 17, 2024

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.

anthonator avatar anthonator commented on July 17, 2024

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.

anthonator avatar anthonator commented on July 17, 2024

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.

anthonator avatar anthonator commented on July 17, 2024

I pushed support for sinatra/json with accompanying tests. Could someone please test against master?

from tilt-jbuilder.

alindeman avatar alindeman commented on July 17, 2024

👍 master has fixed the issue against sinatra/contrib for me

from tilt-jbuilder.

alindeman avatar alindeman commented on July 17, 2024

Any chance you could release a new version to rubygems soon? ❤️

from tilt-jbuilder.

anthonator avatar anthonator commented on July 17, 2024

And done.

from tilt-jbuilder.

Related Issues (8)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.