1

I have a string field in one of my controllers which is a message. I want to embed a clickable link in it.

Something like this works in the view:

<% dd = "Click on link to #{link_to 'View ', "www.google.com"} asdad"  %>
<%= dd.html_safe %> 

but in the controller its not possible to store dd and I get this error:

NoMethodError (undefined method `link_to' for ...

I tried also to_s :

<% dd = "Click on link to #{link_to 'View ', "www.google.com"} asdad".to_s %>  
Message.create(:user_id => current_user.id, :cnt => dd)

but still the same error. Please, help me to know how can I embed a link into string in rails 4.

1 Answer 1

1

Try

in the controller code

view_context.link_to '...', '...'
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you, I've found it some minutes ago, more information for people who will visit this page later: stackoverflow.com/questions/24813895/…

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.