Rails 3: ":method => :post" doesn't work... seems to be 'GET' when it should 'POST' -
i'm trying implement "friendship" in rails 3 app described in railscast 163:self referential assosication
i have set described. using basic user model logis in authlogic works fine. when try add friend using following link:
<% user in @users %> <%=h user.username %> <%= link_to "add friend", friendships_path(:friend_id => user), :method => :post %> <% end %>
i redirect http://localhost:3000/friendships?friend_id=2
, unknown action action 'index' not found friendshipscontroller error no further explanation. expecially strange since have hard coded redirect "user#show" method current user (i.e. redirect profile after adding friend).
if helps, here "friendships#create" method:
def create @friendship = current_user.friendships.build(:friend_id => params[:friend_id]) if @friendship.save flash[:notice] = "added friend." redirect_to :controller => 'users', :action => 'show', :id =>'current_user' else flash[:notice] = "unable add friend." redirect_to :controller => 'users', :action => 'show', :id =>'current_user' end end
any idea causing this? found having similar problem here couldn't find definite fix: rails 3 , friendship models
thanks in advance help!
~dan
i think link_to put arguments query string creating html link if put :method => :post if js disabled.
you simulte post javascript :onclik event.
aniway , use link_to method :post generaly bad idea. in rails use button_to helper pourpose , style link.
edit:
in rails3 doc seems link_to have simulate same behaviur of button_to when called params :method=>:post
(dynamically create html form , submit form ).
but it's not true me in rails 3.0.3 if javascript enabled. investigate.
anyway you should using buttons , forms isn't get; hyperlinks intentionally don't allow methods other get
edit2: ok, rails3 don't create inline form simulate post request via link. in rails3 data-method=post attribute added tag manipulate via javascript function. way request gracefully degradate in call if js disabled.
Comments
Post a Comment