使用Ajax替换基于Onclick事件的页面元素

我正在重新提出这个问题,因为我现在更好地理解了这个问题。 我有一个应用程序有四个模型:用户,产品,品种和季节。 用户
has_many :seasons
has_many :products, :through => :seasons
has_many :varieties, :through => :seasons
产品
has_many :seasons
has_many :users, :through => :seasons
has_many :varieties
品种
belongs_to :product
has_many :seasons
has_many :users, :through => :seasons
四季
belongs_to :product
belongs_to :user
belongs_to :variety
在产品/展示视图中,我列出了特定产品可用的每种品种,以及携带该特定产品的用户。 首次加载产品/展示页面时,我会通过执行以下操作显示所有带有产品的用户:
<% @product.seasons.each do |c| %>  
  <%= link_to c.user.name, c.user %>  
<% end %>
我还列出了产品可用的品种:
<% @product.varieties.each do |c| %>  
  <%= link_to_remote variety.name, :url => variety_path(variety) %>  
<% end %>  
这是Ajax需要发生的地方。当我点击各种名称时,我想用@ variety.seasons替换@ product.seasons循环。我认为这应该只显示具有特定种类的用户。这样看起来像这样:
<% @variety.seasons.each do |c| %>  
  <%= link_to c.user.name, c.user %>  
<% end %>     
我越来越近了,但我无法让它发挥作用。目前,当我点击一个品种时,前端没有任何反应。在日志中,我得到了这个:
Processing VarietiesController#4 (for ip at 2009-09-24 16:02:29) [POST]
  Parameters: {"authenticity_token"=>"9pDgKrHNbg0aMklsQsGl5BQa34bfr0Ft8Fpbxki3XXw="}
ActionController::UnknownAction (No action responded to 4. Actions: check_vendor_role, index, and show)  
日志引用#4并将4称为动作。 4是我点击的项目的品种ID。 这是我的设置: ProductsController的#秀       @product = Product.find(params [:id])       @varieties = @ product.varieties       @users = @ product.users 产品/展示视图     #列出拥有此产品的用户
<div id="userList">  
  <%= render :partial => "products/users" %>  
</div>  

#Lists the varieties available for this product  

<% @product.varieties.each do |variety| %>  
  <%= link_to_remote variety.name, :url => variety_path(variety) %>  
<% end %>  
VarietiesController#表演。
  def show
   @variety = Variety.find(params[:id])
    respond_to do |format|
      format.html
      format.xml  { render :xml => @variety}
      format.js
    end
  end
品种/ show.js.rjs     @ page.replace_html“userList”,:partial =>“products / users”,:collection => @ variety.users 因此,目前,该页面正在呈现并显示正确的html和数据。但是onclick没有运作。当我点击各种各样时,应用程序无法正确处理请求,用户列表也不会更改。 更新 回应Anatoliy的评论: 我不确定究竟需要添加哪条路线。我尝试添加以下内容,但结果与之前相同: map.resources:variety,:member => {:show =>:get} 您能否更具体地说明应该调用哪条成员路线?     
已邀请:
正如评论中所述(应列为答案): 添加:method =>:进入link_to_remote调用,使用正确的HTTP动词对该URL进行“show”。     
&lt; div id =“userList”>应该是&lt; div id =“users”>     

要回复问题请先登录注册