Forum: Ruby on Rails Helpers in lib

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Mark (Guest)
on 2008-11-19 12:35
(Received via mailing list)
Hi all,

I have a query about how to access helper methods in a library. I'm
trying to create a custom liquid drop thing which has a form in it (a
poll), and I'm unable to get form_for to work with "vote_poll_path".

Here's my code for the custom drop (this is in a file in lib):

def render(context)
  @vote = =>
  output = "<div class='poll'><a href='/polls/#{}'>#
  output += context.capture(form_for @vote, :url =>
  for choice in @poll.choices
      output += "<input type='radio' name='choice_id'' value='#
  output += "</div>"
  output += "<input type='submit' value='Vote!' />"
  output += "<% end %>"

And here's the error I get:

Liquid error: undefined method `vote_poll_path’ for #

I've watched Railscast episode 132 (helpers outside views) for some
information on how to do this but I'm still stuck. At the end he
mentions @template but I can't get that to work either, it gets
evaluated as nil. I'd be really grateful for any help.


This topic is locked and can not be replied to.