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

upgrade to operate in line with new Rails 3 helper blocks #4

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

fastcatch
Copy link

modified code to operate in line with the new Rails3 helper block syntax and updated documentation

@vptcnt
Copy link

vptcnt commented May 20, 2012

Hi Fastcatch,

I tried your fork and the example of SubNav is not working on Rails 3.2.3

Each time I call the sub_nav witha block, I have the following error :
(eval):1: syntax error, unexpected $undefined
$#<VincentHelper::Nav::S...
 ^

Extracted source (around line #19):

16: 
17: <% nav do |n|
18:   n.titi
19:   n.sub_nav do |s|
20:    s.toto
21:   end
22: end
23: %>

If there is no block for the method sub_nav, is working - no error but no display

The source code is :

module VincentHelper
  class Nav < BlockHelpers::Base
    #...code....
    def titi
      "titi"
    end

    class SubNav < BlockHelpers::Base
      #...code...
      def toto
        "toto"
      end
    end
  end

Thanks for your help

@fastcatch
Copy link
Author

It seems that your code is missing a few "=" signs:

<%= nav do |n| %>
<%=    n.titi %>
<%=   n.sub_nav do |s| %>
<%=    s.toto %>
<%  end %>
<% end %>

works fine. It's not very convenient but that's as good as it gets.

If you want fewer '=' signs (and willing to go back to Rails 2.x output logic), redefine rails2_compatibility_mode to true and write:

<% nav do |n| %>
<%=    n.titi %>
<%   n.sub_nav do |s| %>
<%=    s.toto %>
<%  end %>
<% end %>

For the record I tested it on 3.0.7 and ruby 1.8.7 but it shouldn't make any difference.

@vptcnt
Copy link

vptcnt commented May 21, 2012

Thanks

I put the =, but it's not working
I am using Rails 3.2.3 and ruby 1.9.3

(eval):1: syntax error, unexpected $undefined
$#<TestHelper::Nav::SubNav:0x3...
 ^

Extracted source (around line #3):

1: <%= nav do |h| %>
2:   <%= h.toto %>
3:   <%= h.sub_nav do |m| %>
4:         <%= m.titi %>
5:   <% end %>
6: <% end %>

The source code

module TestHelper

  class Nav < BlockHelpers::Base
    #...code....
    def toto
      "toto"
    end

    class SubNav < BlockHelpers::Base
      #...code...
      def titi
        "titi"
      end
    end
  end
end

If I DON'T call sub_nav with a block, like this :

<%= nav do |h| %>
  <%= h.toto %>
  <%= h.sub_nav %>
<% end %>

I have no error but it displays :

toto 
#<TestHelper::Nav::SubNav:0x375c480> 

@fastcatch
Copy link
Author

Sorry to hear. I'll check with newer Rails and ruby when I get to it (perhaps 1-2 days), and I'll get back to you. (I guess it's gonna be the ruby for 1.9.x handles blocks a bit different from 1.8.x.)

@fastcatch
Copy link
Author

It turns out that changes in Rails (ActiveSupport -- to be more precise) cause the breakdown. See this comment and this commit if interested. (I'm seriously surprised at how few projects/people have complained so far overall...) I seem to have got it fixed, though. Not pretty but does the job.

@vptcnt
Copy link

vptcnt commented May 23, 2012

Thanks it's workiung !
Maybe it will be good to bump to a new version 0.3.4 or 0.4

One thing : For your version , I should put in my gemfile :

gem "block_helpers", :git => "git://github.com/fastcatch/block_helpers.git", :ref => "64a28acf0de4"

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

Successfully merging this pull request may close these issues.

2 participants