# How to call a method in a controller with link\_to?

**URL:** <https://www.ruby-forum.com/t/how-to-call-a-method-in-a-controller-with-link-to/195539>\
**Category:** Rails\
**Created:** [September 24, 2010, 7:49pm UTC](https://www.ruby-forum.com/t/how-to-call-a-method-in-a-controller-with-link-to/195539 "2010-09-24T19:49:21Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![rodrigo3n](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/a8b319/32.png) [@rodrigo3n](https://www.ruby-forum.com/u/rodrigo3n)\
**Post date:** [September 24, 2010, 7:49pm UTC](https://www.ruby-forum.com/t/how-to-call-a-method-in-a-controller-with-link-to/195539/1 "2010-09-24T19:49:21Z")

</div>

Hello everyone, I have a MessagesController created with rails g  
scaffold and the user may create messages that get saved, in tihs  
controller I have a method called ‘tweet’ that (using the twitter  
gem / Twitter API) triggers the given message to twitter. However I  
don’t know how to put a tweet link in my /tweets/index.html.erb… you  
know this link won’t be calling an action (edit, destroy, new), this  
link will be calling a method created by myself in the controller. Can  
you help me?

P.S: I am using rails 3.

Thanks!

Rodrigo Alves V.

---

<div class="post-metadata">

**Author:** ![rodrigo3n](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/a8b319/32.png) [@rodrigo3n](https://www.ruby-forum.com/u/rodrigo3n)\
**Post date:** [September 24, 2010, 8:37pm UTC](https://www.ruby-forum.com/t/how-to-call-a-method-in-a-controller-with-link-to/195539/2 "2010-09-24T20:37:49Z")

</div>

routes.rb

resources :messages do  
member do  
get :tweet  
end  
end

should give you a tweet\_message\_path to use in a view like

\<%= link\_to(‘Tweet This’, tweet\_message\_path(message.id)) %\>

and direct the app to your tweet method in the messages\_controller
