开发者

How do I create a path to create followers in rails 3?

I am using acts_as_followers and want to know have a path that I can pass to a link_to :remote => true link so that a User can follower various different entities.

Here is what I have in the routes (via rake routes)

follow

/users/follow/:followed_type/:followed_id(.:format) {:controller=>"users", :action=>"follow_this"}

This is what is in routes.rb:

match 'users/follow/:followed_type/:followed_id' => 'users#follow_this', :as => "follow"

But I'm not clear how I pass the values into the URL string using the path helper? I need to pass in the type as a string (e.g. "Vendor"), and the :id...but how do I do that?

This was i can enable a user to press the link and it will call this action and create the following relationship.

46   def follo开发者_JAVA百科ws_this
 47 
 48     followed_type = params[:followed_type]
 49     followed_class = class_type.camelize.constantize
 50     followed = followed_class.find(params[:followed_id])
 51     current_user.follow(followed)  #uses acts_as_follower plugin
 52 
 53   end


put '/users/follow/:followed_type/:followed_id' => 'users#follow_this', :as => "follow"

usage

<%= link_to "Follow White Rabbit", follow_path(:followed_type => "some type", :followed_id => "some_id"), :method => :put %>

match means you can call ANY of requests: GET, POST, PUT or DELETE. So it better to specify wich one you want to use. As far as you updating some data - use PUT, if you are creating some data - POST, if you are deleting - DELETE and if you just fetch - GET

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜