Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Json.partial! doesn't work #6

Open
ownadi opened this issue Sep 17, 2014 · 11 comments
Open

Json.partial! doesn't work #6

ownadi opened this issue Sep 17, 2014 · 11 comments

Comments

@ownadi
Copy link

ownadi commented Sep 17, 2014

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
Copy link

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

@linchus
Copy link

linchus commented Jul 13, 2015

You should update tilt-jbuilder gem to 0.7.0.

It is fixed in new version.

@katpadi
Copy link

katpadi commented Oct 1, 2015

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

@linchus
Copy link

linchus commented Oct 1, 2015

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

@katpadi
Copy link

katpadi commented Oct 1, 2015

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'
  • ruby 2.1.2
  • rails (4.1.8)
  • grape (0.12.0)
  • grape-jbuilder (0.2.0)
  • jbuilder (2.3.1)

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
Copy link

linchus commented Oct 1, 2015

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

Tilt just cannot find your partial

@katpadi
Copy link

katpadi commented Oct 1, 2015

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
Copy link

linchus commented Oct 1, 2015

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
Copy link

vyorkin commented Dec 13, 2015

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

@katpadi
Copy link

katpadi commented Dec 13, 2015

Hello! You can close this now. Thank you!
On Dec 13, 2015 11:40 PM, "Vasiliy Yorkin" [email protected] 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
#6 (comment)
.

@jibiel
Copy link

jibiel commented Dec 1, 2016

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants