[jquery] 在prototype中link_to :method的用法 在juqery里面失效~

7 views
Skip to first unread message

B.Tag

unread,
Aug 5, 2011, 12:41:39 AM8/5/11
to chengdu...@googlegroups.com
re....
我怎么把这条代码修改成jquery的提交
<%= link_to "Add Friend","friendship?friend_id=#{user.id}", :method => "post" %>

我尝试了下别的 都不可用,google 上也没找到头绪~~~


friendship 的控制器:
# -*- coding: UTF-8 -*-
class FriendshipController < ApplicationController
  def create
    @friendship =  @current_user.friendship.build(:friend_id => params[:friend_id])#Friendship.new(params[:friendship])
    if @friendship.save
      flash[:notice] = "Added friend"
      #redirect_to root_url
      respond_to do |format|
        #format.html{redirect_to @friendship.}
        format.js
      end
    else
      flash[:error] = "Unable to add friend"
      redirect_to root_url
    end
  end
  
  def destroy
    @friendship = Friendship.find(params[:id])
    @friendship.destroy
    flash[:notice] = "delete friend"
    redirect_to :controller => 'user',:action => 'show'
  end
end

--
-------------------------------------------------------------------------
        learn log: http://me.boolsir.com 
        my life log: http://www.boolsir.com
-------------------------------------------------------------------------

vkill.net

unread,
Aug 5, 2011, 12:59:57 AM8/5/11
to chengdu...@googlegroups.com
link_to 中为啥不用 router_helper 呢?

B.Tag

unread,
Aug 5, 2011, 1:37:56 AM8/5/11
to chengdu...@googlegroups.com
对rails 不是很熟悉 。。能给个列子吗?

在 2011年8月5日 下午12:59,vkill.net <vkill.net@gmail.com>写道:
link_to 中为啥不用 router_helper 呢?

--
成都 Ruby on Rails 邮件列表:
发贴请Email至:chengdu...@googlegroups.com
https://groups.google.com/group/chengduonrails?hl=zh-CN

邰健聪

unread,
Aug 5, 2011, 3:49:25 AM8/5/11
to chengdu...@googlegroups.com
:method => symbol of HTTP verb - This modifier will dynamically create an HTML form and immediately submit the form for processing using the HTTP verb specified. Useful for having links perform a POST operation in dangerous actions like deleting a record (which search bots can follow while spidering your site). Supported verbs are :post:delete and :put. Note that if the user has JavaScript disabled, the request will fall back to using GET. If :href => '#' is used and the user has JavaScript disabled clicking the link will have no effect. If you are relying on the POST behavior, you should check for it in your controller’s action by using the request object’s methods for post?delete? or put?.

试试symbol

2011/8/5 B.Tag <bb....@gmail.com>

B.Tag

unread,
Aug 5, 2011, 4:16:43 AM8/5/11
to chengdu...@googlegroups.com
搞定了~~~ 我把friendship create 和destroy 放发哦user的控制器下了。

然后用get方式传送~~

用POST返回一个 500错误~~排查中·~

Terry Tai

unread,
Aug 20, 2011, 10:08:53 PM8/20/11
to chengdu...@googlegroups.com
给我你 rake routes的结果

通常不会在link_to 中去做post
如果需要你这里可以是一个 ajax post

看你的url感觉上看 感觉你设计上怪怪的….







-- 
Terry Tai
Sent with Sparrow

在 2011年8月21日星期日,上午9:51,Terry Tai 写道:

show me your routes.
rails默认post参数不是放url
Terry Tai
---------------------------------------------
My twitter: twitter.com/poshboytl
My blog: terrytai.com

Reply all
Reply to author
Forward
0 new messages