milkcocoa / grape-jbuilder

Use Jbuilder with Grape
MIT License
49 stars 18 forks source link

Json.partial! doesn't work #6

Open ownadi opened 10 years ago

ownadi commented 10 years ago

json.array! Item.all, partial: 'item', as: :item throws exception TypeError: {:partial=>"item", :as=>:item} is not a symbol

ruby 2.1.2 rails 4.1.6

ryanbillingsley commented 9 years ago

Running into this same exact problem. This issue from JBuilder may have something to do with it?

linchus commented 9 years ago

You should update tilt-jbuilder gem to 0.7.0.

It is fixed in new version.

katpadi commented 9 years ago

I'm trying json.partial! 'path_to_partial' but I'm getting ArgumentError (file or block required).

linchus commented 9 years ago

Please, show full stacktrace, bundle list output and your template. Do you have partial with path path_to_partial?

katpadi commented 9 years ago

Hi! Here...

ArgumentError (file or block required):
/Users/katpadi/.rvm/gems/ruby-2.1.2@xxx/gems/tilt-1.4.1/lib/tilt/template.rb:51:in `initialize'
/Users/katpadi/.rvm/gems/ruby-2.1.2@xxx/gems/tilt-jbuilder-0.7.0/lib/tilt/jbuilder.rb:25:in `new'
/Users/katpadi/.rvm/gems/ruby-2.1.2@xxx/gems/tilt-jbuilder-0.7.0/lib/tilt/jbuilder.rb:25:in `partial!'
/Users/katpadi/xxx/app/views/api/v1/somethings/something.jbuilder:2:in `block (3 levels) in evaluate'
/Users/katpadi/.rvm/gems/ruby-2.1.2@xxx/gems/jbuilder-2.3.1/lib/jbuilder.rb:298:in `block (2 levels) in _map_collection'
/Users/katpadi/.rvm/gems/ruby-2.1.2@xxx/gems/jbuilder-2.3.1/lib/jbuilder.rb:305:in `_scope'
/Users/katpadi/.rvm/gems/ruby-2.1.2@xxx/gems/jbuilder-2.3.1/lib/jbuilder.rb:298:in `block in _map_collection'
/Users/katpadi/.rvm/gems/ruby-2.1.2@xxx/gems/jbuilder-2.3.1/lib/jbuilder.rb:297:in `map'
/Users/katpadi/.rvm/gems/ruby-2.1.2@xxx/gems/jbuilder-2.3.1/lib/jbuilder.rb:297:in `_map_collection'
/Users/katpadi/.rvm/gems/ruby-2.1.2@xxx/gems/jbuilder-2.3.1/lib/jbuilder.rb:188:in `array!'
/Users/katpadi/.rvm/gems/ruby-2.1.2@xxx/gems/tilt-jbuilder-0.7.0/lib/tilt/jbuilder.rb:35:in `array!'
/Users/katpadi/xxx/app/views/api/v1/somethings/something.jbuilder:1:in `block (2 levels) in evaluate'

I tried in my console:

Tilt::JbuilderTemplate.new("views/some_dir/_partial.jbuilder")

and it works. I just can't use json.partial! in my jbuilder file.

I am calling it like this

json.partial! 'some_dir/partial'
linchus commented 9 years ago

I think you should check your template view_path in app and partial name in template.

Tilt just cannot find your partial

katpadi commented 9 years ago

I explicitly defined view_path and it worked!

json.partial! 'some_dir/partial', view_path: Rails.root.join("app", "views", "api", "v1")

I wonder why it's not being picked up automatically?

linchus commented 9 years ago

The view_path in rails app is Rails.root.join("app", "views") if I am right. You should set partial name from this dir, for instance: json.partial! 'api/v1/some_dir/partial'

vyorkin commented 8 years ago

@ownadi @katpadi @ryanbillingsley Is everything ok? @milkcocoa Can we close this?

katpadi commented 8 years ago

Hello! You can close this now. Thank you! On Dec 13, 2015 11:40 PM, "Vasiliy Yorkin" notifications@github.com wrote:

@ownadi https://github.com/ownadi @katpadi https://github.com/katpadi @ryanbillingsley https://github.com/ryanbillingsley Is everything ok? @milkcocoa https://github.com/milkcocoa Can we close this?

— Reply to this email directly or view it on GitHub https://github.com/milkcocoa/grape-jbuilder/issues/6#issuecomment-164269139 .

jibiel commented 7 years ago

Got it working with:

require 'grape/jbuilder'

use Rack::Config do |env|
  env['api.tilt.root'] = 'app/views/api/'
end

as per README.md.

json.partial! 'v1/resources/resource', resource: @resource