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

Use params of locals pass on Rabl::Engine to be method #269

Closed
wants to merge 1 commit into
from

Conversation

Projects
None yet
3 participants
@shingara
Contributor

shingara commented Jun 12, 2012

When you pass locals params on your Rabl.render you can now use it like
instance method in your rabl view. By example if you have a view like :

object blog
attributes :content, :title

you can define your blog elements directly in you Rabl.render like :

Rabl.render(nil, 'blog/show', {
  :view_paths => 'app/view',
  :locals => { :blog => Blog.new }
})
@nesquena

This comment has been minimized.

Show comment
Hide comment
@nesquena

nesquena Jun 12, 2012

Owner

@shingara Interesting concept, can you add a quick test for this functionality

Owner

nesquena commented Jun 12, 2012

@shingara Interesting concept, can you add a quick test for this functionality

@databyte

This comment has been minimized.

Show comment
Hide comment
@databyte

databyte Jul 11, 2012

Collaborator

Hmm. Render already takes in object as a parameter so doesn't it just make sense to pass it? You opted to pass in nil and then created a locals hash to place the object in there.

Normally we pass around a single object (for instance with partial) and allow it to override the object call within the template.

I think introducing the idea of locals and then referencing a "local" within the template adds to the confusion. Especially if you use the "local" for rendering but when using the template through the web framework, it doesn't access to the same locals hash.

Shouldn't an object simply be an object? We should follow a single standard of overriding and passing in objects.

Collaborator

databyte commented Jul 11, 2012

Hmm. Render already takes in object as a parameter so doesn't it just make sense to pass it? You opted to pass in nil and then created a locals hash to place the object in there.

Normally we pass around a single object (for instance with partial) and allow it to override the object call within the template.

I think introducing the idea of locals and then referencing a "local" within the template adds to the confusion. Especially if you use the "local" for rendering but when using the template through the web framework, it doesn't access to the same locals hash.

Shouldn't an object simply be an object? We should follow a single standard of overriding and passing in objects.

@nesquena

This comment has been minimized.

Show comment
Hide comment
@nesquena

nesquena Jul 11, 2012

Owner

Yeah I think that's a good point. Was still mulling it over, I do feel that locals might be unnecessary, I rarely find myself missing a locals hash in my APIs. Perhaps if people had a compelling use case.

Owner

nesquena commented Jul 11, 2012

Yeah I think that's a good point. Was still mulling it over, I do feel that locals might be unnecessary, I rarely find myself missing a locals hash in my APIs. Perhaps if people had a compelling use case.

@shingara

This comment has been minimized.

Show comment
Hide comment
@shingara

shingara Jul 12, 2012

Contributor

My example on commit is not the most explicit use case. To me the use case is when I want mix some data in same output. By example using other data than object or collection in my output. To do that I need generate an specific objet to my rabl output mixin this value.

object blog
attributes :content, :title
child(:current_user) {
  code (:name) { current_user.name }
}

This rabl view works fine in controller environment. But I can't generate it by Rabl.render because I can't override the current_user method.

Contributor

shingara commented Jul 12, 2012

My example on commit is not the most explicit use case. To me the use case is when I want mix some data in same output. By example using other data than object or collection in my output. To do that I need generate an specific objet to my rabl output mixin this value.

object blog
attributes :content, :title
child(:current_user) {
  code (:name) { current_user.name }
}

This rabl view works fine in controller environment. But I can't generate it by Rabl.render because I can't override the current_user method.

Use params of locals pass on Rabl::Engine to be method
When you pass locals params on your Rabl.render you can now use it like
instance method in your rabl view. By example if you have a view like :

```ruby
object blog
attributes :content, :title
```

you can define your blog elements directly in you Rabl.render like :

```ruby
Rabl.render(nil, 'blog/show', {
  :view_paths => 'app/view',
  :locals => { :blog => Blog.new }
})
```
@databyte

This comment has been minimized.

Show comment
Hide comment
@databyte

databyte Aug 6, 2012

Collaborator

Opting for #297 but thanks for the attempt. I'll provide you with credit for coming up with another solution. 😁

Collaborator

databyte commented Aug 6, 2012

Opting for #297 but thanks for the attempt. I'll provide you with credit for coming up with another solution. 😁

@databyte databyte closed this Aug 6, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment