Reputation: 1000
Can anyone point me in the right direction to learn about how I could implement a system similar to facebook's "like" or Twitter's "Follow/Unfollow" system that I could create in Rails?
From what I understand I would need to use Unobtrusive Javascript.
I have a Thing model(has_many :likes) and a Like model (belongs_to :thing)
Any pointers?
Upvotes: 1
Views: 1082
Reputation: 717
You can do ajax call to a function and implement whatever functionality you like inside that function , (in this case "follow" ), you can do it with :
[link_to_function][1]
Incase , you are using rails 3.2.4 and it deprecated, you can use(This is from jeremy's comment. https://gist.github.com/rails/rails/pull/5922#issuecomment-5770442 ):
module LinkToFunctionHelper
def link_to_function(name, *args, &block)
html_options = args.extract_options!.symbolize_keys
function = block_given? ? update_page(&block) : args[0] || ''
onclick = "#{"#{html_options[:onclick]}; " if html_options[:onclick]}#{function}; return false;"
href = html_options[:href] || '#'
content_tag(:a, name, html_options.merge(:href => href, :onclick => onclick))
end
end
Upvotes: 1