How to put link_to inside a line on rails

Here I found a similar Rails 3 link_to question inside a line , but for some reason does not work for my script.

I have an object @matterthat has a url as shown below.

@matter = url_for(:controller => 'news', :action => 'news_view',:id => @news.token)

I'm trying to put this link inside the text, which can be done by simply placing "# {@matter}". But I want to put the alias of this entire link generated as "VIEW NEWS", and when the user clicks on it, it is redirected to the original url.

Using this, I must send both my mail and mobile text to my link. I received it by e-mail, but could not do this to send text, as it :bodyrequires a string format for the message API.

I followed the aforementioned SO post, but they don't work for me at all.

"\"#{@news.sender.first_name} #{@news.sender.last_name} just sent you a invite.\" Click on link raw('<%= link_to 'View Invite', @method) %>') ")

I agree with the use of html inside the string, for example <a href ="#{@matter}", view invite </a>, if possible.

Help Wanted.

I use twilio to send text using below API.

  @client = Twilio::REST::Client.new @account_sid, @auth_token
  @client.account.messages.create(:from => '+123456789', :to => '+1'+@phone, 
                                  :body => "#{@matter}" )
+4
source share
2 answers

You can do the following:

"#{@news.sender.first_name} #{@news.sender.first_name} just sent you an invite."
"Click on link to #{link_to 'View invite', @matter}".html_safe

If you use your controller, you can access your view_context:

def show
  # ...
  @message  = "#{@news.sender.first_name} #{@news.sender.first_name} just sent you an invite."
  @message << "Click on link to #{view_context.link_to 'View invite', @matter}"

  @client = Twilio::REST::Client.new @account_sid, @auth_token
  @client.account.messages.create(:from => '+123456789', :to => '+1'+@phone, 
                              :body => @message.html_safe )
end
+6
source

, - . iPhone. , - , , .

0

All Articles