开发者

Simple link_to_remote function - can't get it to work

开发者 https://www.devze.com 2023-01-17 02:26 出处:网络
After utilizing the great trial and error for over an hour along with dozens of tutorials and blogs posting examples, I still cannot get the simple ajax functionality to work.Here is what is in my par

After utilizing the great trial and error for over an hour along with dozens of tutorials and blogs posting examples, I still cannot get the simple ajax functionality to work. Here is what is in my partial:

<span id="friend">
  <%= link_to_remote image_submit_tag("/images/add_as_friend.gif"), :url => {:controller => 'friends', :action => 'add', :id => id} %>
</span>

This is what is in my controller:

class FriendsController < ApplicationController
  def add
    unless params[:id].nil?
      Friend.create(:user_id => @current_us开发者_运维问答er.id, :friend_id => params[:id], :friend_type => 2)
    end
  end
end

This is what is in my add.rjs file:

page.replace_html 'friend', "A request to be friends with this player has been sent."

The image for the link comes up fine. When I click on it, however, nothing happens. I've checked the database and nothing is going on. I must be missing something, any thoughts?


It may be because you are using image_submit_tag rather than image_tag for the content of your link. image_submit_tag is for submitting forms so will have its own onclick behaviour which may override the onclick behaviour that will be added as part of the link_to_remote functionality.

I would try:

<%= link_to_remote image_tag("/images/add_as_friend.gif"), 
    :url => {:controller => 'friends', :action => 'add', :id => id} %>
0

精彩评论

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