Giter Site home page Giter Site logo

Comments (5)

anthonator avatar anthonator commented on July 17, 2024

Can you snd some code over the exhibits the behavior?

from tilt-jbuilder.

subvertallchris avatar subvertallchris commented on July 17, 2024

Sure, but it's not too exciting.

module Sinatra
  module APIv1::Reports

    def self.registered(app)
      app.namespace %r{^/v1} do
        get '/reports/?' do
          template = Tilt::JbuilderTemplate.new("#{app.views}/v1/reports/index.json.jbuilder")
          template.render
        end
      end
    end
  end

  register APIv1::Reports
end

Then within index.json.jbuilder...

json.partial! :partial_name

...results in...

     ArgumentError:
       file or block required
     # /Users/cgrigg/.rvm/gems/ruby-2.2.0/gems/tilt-1.4.1/lib/tilt/template.rb:51:in `initialize'
     # /Users/cgrigg/.rvm/gems/ruby-2.2.0/gems/tilt-jbuilder-0.6.1/lib/tilt/jbuilder.rb:14:in `new'
     # /Users/cgrigg/.rvm/gems/ruby-2.2.0/gems/tilt-jbuilder-0.6.1/lib/tilt/jbuilder.rb:14:in `partial!'
     # ./app/views/v1/reports/index.json.jbuilder:1:in `block (2 levels) in evaluate'

I think it's happening because view_path is returning nil at https://github.com/anthonator/tilt-jbuilder/blob/master/lib/tilt/jbuilder.rb#L13.

from tilt-jbuilder.

subvertallchris avatar subvertallchris commented on July 17, 2024

If I make this adjustment:

    def partial!(template_name, locals = {})
      locals.merge! :json => self
      template_path = locals.extract!(:template_path)[:template_path]
      view_path = @scope.instance_variable_get('@_jbuilder_view_path') ||  ::Sinatra::Application.views
      file = fetch_partial_path(template_name.to_s, view_path)
      template = ::Tilt::JbuilderTemplate.new(file, nil, nil)
      template.render(@scope, locals)
    end

I'm able to do this in my template:

json.partial! 'v1/reports/omg'

And it works. Would love not to do this but it'll work for the time being.

from tilt-jbuilder.

anthonator avatar anthonator commented on July 17, 2024

Sorry for not being very responsive!

Does jbuilder let you provide a symbol to render a partial? I don't think it does. Is there a reason you need to use a symbol over a string?

from tilt-jbuilder.

anthonator avatar anthonator commented on July 17, 2024

Closing due to lack of response. Reopen if you would still like to discuss.

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.