Forum: Ruby on Rails Helpers in lib

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community 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 = Vote.new(:poll_id => @poll.id)
  output = "<div class='poll'><a href='/polls/#{@poll.id}'>#
{@poll.question}</a>"
  output += context.capture(form_for @vote, :url =>
context.vote_poll_path(@vote.poll))
  for choice in @poll.choices
      output += "<input type='radio' name='choice_id'' value='#
{choice.id}'>#{choice.description}</input>"
  end
  output += "</div>"
  output += "<input type='submit' value='Vote!' />"
  output += "<% end %>"
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.

Thanks,

Mark
This topic is locked and can not be replied to.