0
def helper_method
   "<a href='#{movie_path(user.wants_to_see_movies.first)}'>#{user.wants_to_see_movies.first.title.titleize}</a>".html_safe
end

I'm trying to generate a link from above helper method but instead it's showing up as Wants to see <a href='/movies/2'>Spectre</a> in the view.

  1. First, what am I doing wrong? I thought html_safe would solve this.
  2. Is there a way to do this with a link_to instead?
2
  • Are you calling your helper method directly from the view or via another helper method? Commented Nov 27, 2015 at 0:20
  • directly from the view Commented Nov 27, 2015 at 0:52

1 Answer 1

5

I'm not certain as to why html_safe isn't working but you should be able to use link_to like

def helper_method
  movie = user.wants_to_see_movies.first
  link_to movie.title.titleize, movie
end
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.