Comments (22)
@thenetduck I think I have already got this working (i.e you can access all route and helper methods in RABL templates). I can't push to GH right now because the partition that RABL is on is full but once I do it would be great if you could test the 'edge' rabl in the repo and confirm helpers now work. Will comment again when they free up space and I can push.
from rabl.
@thenetduck Ok view helpers should be fully accessible now in git version, can you try and get back to me?
gem 'rabl', :git => "git://github.com/nesquena/rabl.git"
from rabl.
@nesquena its working on my side using the git version, for sake of testing I used a Date Helper and Translation Helper
=== in rabl template collection @compute_types attributes :id, :name node(:created) {|compute_type| time_ago_in_words(compute_type.created_at) + t('common.ago', :default => ' ago')} === in response body [{ "compute_type": { "created": "2 months ago", "name": "Amazing Compute", "id": 66 } }]
from rabl.
Ok great, I will release a new gem version, thanks!
from rabl.
Hey guys sorry I feel asleep :) Sounds like its working. I'll implement and give some feedback here in a couple of hours.
You guys rock! Thanks
from rabl.
@thenetduck Thanks let me know if it works and if you run into any other issues.
from rabl.
I don't know if this is realated but in rails I get this error when the gem is installed
No such file or directory - git ls-files
I read this article http://rubyroyd.com/2010/11/17/no-such-file-or-directory-git-ls-files
I'm using rvm + passenger + rails and don't know if that effects anything. Is this a local issue or a gem issue?
from rabl.
Yeah seems like an issue with the way the gemspec works: https://github.com/nesquena/rabl/blob/master/rabl.gemspec
Although that is the stock bundler generated gemspec type template. Seems like it isn't able to find the git executable. Does this prevent the Rails app from running when RABL is in the Gemfile?
from rabl.
Yes. It breaks my app. This is interesting though. If I have this
gem 'rabl'
it works just fine, however if I'm pointing to your git repo
gem 'rabl', :git => "git://github.com/nesquena/rabl.git"
This breaks it.
from rabl.
Fascinating, so using the gem version, everything is OK? I have used both and never run into this problem. I guess just stick to stable for now :|
from rabl.
yoki dokie
from rabl.
Let me know if you run into any other issues, thanks!
from rabl.
Is this feature working? It was closed a year ago but I am still seeing it in the gem. Maybe I should use the Github version?
from rabl.
Can you post an example of what isn't working. Are you using Rails? What version? If it helps here's the line that should be proxying to the 'context_scope' (i.e the controller): https://github.com/nesquena/rabl/blob/master/lib/rabl/engine.rb#L242
from rabl.
Yes, I'm using Rails 3.2.3. The error I am getting is
NoMethodError (undefined method `strip_tags' for
#Rabl::Engine:0x007fc8a0750f10): app/views/api/events.rabl:8:in `block (2 levels) in render'
The context of the code where this is thrown is as follows:
child(@events) {
node(:description){|m|
strip_tags(m.description)
}
}
On Sun, Jul 15, 2012 at 6:09 PM, Nathan Esquenazi <
[email protected]
wrote:
context_scope
from rabl.
Interesting, I'll take look soon and hopefully fix this. That is odd.
from rabl.
I'm seeing the same issue as well. Using Rails 3.2.6. Haven't tried it with a previous rails version though, so I'm not sure if it was working before.
from rabl.
its not working for me too (Rails 3.2.6, RABL 0.7.1):
node(:created_at){ |x| time_ago_in_words(x.created_at) }
# => undefined method `time_ago_in_words' for #<Rabl::Engine:0x007fb584931e08>
from rabl.
It's possible it's a scoping problem or something odd with your rendering process.
The best thing to do is throw a debugger in a node there and see what x
is. Sometimes the helpers and values are not where you'd expect them to be.
node(:debug_me) {|x| debugger; puts x }
If you're not familiar with debugging RABL directly, I actually wrote a little blog post on it with examples in RABL including links back to Issues like this. Scroll down to "I HAZ DEBUGGER!" for the examples.
I also reconfirmed that RABL didn't break anything. I just pushed another test showing your exact case.
Here are the results:
{
"article"=>{
"title"=>"Foo",
"body"=>"Bar",
"posted_at"=>"2012-08-07T14:30:36Z",
"created_date"=>{
"day"=>7,
"hour"=>14,
"full"=>"2012-08-07T14:30:36Z"
},
"post"=>[
"Foo",
"Bar"
],
"foo"=>"BAR!", # helper call already being tested
"created_at_in_words"=>"less than a minute", # helper just added
"user"=>{
# snip
},
"author_name"=>"billybob"
}
}
from rabl.
This works for me but I don't know how to spec now.
Example where I'm using truncate
in my rabl view:
Rabl.render(post, 'beta/posts/show')
Failure/Error: Rabl.render(post, 'beta/posts/show')
NoMethodError:
undefined method `truncate' for #<Rabl::Engine:0x007fdd911775c0>
Any idea please?
from rabl.
In my case, I was defining the helper in the controller using the standard def, but the method did not work in the rabl views. What fixed it for me is to use the helper_method macro:
helper_method :current_user
def current_user
...
end
Without the helper_method macro, the method is not accessible from the view.
from rabl.
helper not word in rabl with rails 4, I use mater still have that problem
from rabl.
Related Issues (20)
- Drop riot? Unmaintained, broken on Ruby 2.5. HOT 2
- How to use rabl with swagger? HOT 2
- Tagging a new version, or use master branch? HOT 1
- Unable to properly render json for an simple array of objects HOT 1
- How do I render free form metadata HOT 1
- Migrating to Rails 5 - Rabl returning Active Record object
- Rspec renders rabl as string instead of json
- Not able to get the rendered result in Rails console HOT 1
- Rabl output values as keys
- Rabl partial lookup based on requested api namespace
- upgrading from 0.14.0 to 0.14.1 is a breaking change HOT 8
- Child removes node from response when the provided object is an empty array HOT 2
- Rabl not renders collection properly HOT 4
- Is nested map valid in RABL?
- N+1 issues HOT 1
- some problems to install rable on windows HOT 2
- Avoid playing with `Oj` shared `default_options` HOT 2
- rabl tests failing with rr 3.x and Ruby 3 HOT 12
- Rails 7 compatibility HOT 1
- access controller instance variables in representers
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rabl.