Coder Social home page Coder Social logo

Comments (22)

nesquena avatar nesquena commented on July 19, 2024

@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.

nesquena avatar nesquena commented on July 19, 2024

@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.

mpagalan avatar mpagalan commented on July 19, 2024

@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.

nesquena avatar nesquena commented on July 19, 2024

Ok great, I will release a new gem version, thanks!

from rabl.

fourcolors avatar fourcolors commented on July 19, 2024

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.

nesquena avatar nesquena commented on July 19, 2024

@thenetduck Thanks let me know if it works and if you run into any other issues.

from rabl.

fourcolors avatar fourcolors commented on July 19, 2024

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.

nesquena avatar nesquena commented on July 19, 2024

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.

fourcolors avatar fourcolors commented on July 19, 2024

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.

nesquena avatar nesquena commented on July 19, 2024

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.

fourcolors avatar fourcolors commented on July 19, 2024

yoki dokie

from rabl.

nesquena avatar nesquena commented on July 19, 2024

Let me know if you run into any other issues, thanks!

from rabl.

volkanunsal avatar volkanunsal commented on July 19, 2024

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.

nesquena avatar nesquena commented on July 19, 2024

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.

volkanunsal avatar volkanunsal commented on July 19, 2024

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.

nesquena avatar nesquena commented on July 19, 2024

Interesting, I'll take look soon and hopefully fix this. That is odd.

from rabl.

dkharrat avatar dkharrat commented on July 19, 2024

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.

ekorneeff avatar ekorneeff commented on July 19, 2024

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.

databyte avatar databyte commented on July 19, 2024

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.

apneadiving avatar apneadiving commented on July 19, 2024

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.

dkharrat avatar dkharrat commented on July 19, 2024

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.

scalaview avatar scalaview commented on July 19, 2024

helper not word in rabl with rails 4, I use mater still have that problem

from rabl.

Related Issues (20)

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.