I am having problems with link_to remotely sending a message to another controller ... The result is not quite what I expect.
I have this in node_content.html.erb:
<% @node.videos.each do |vid| %> <div id="vid_vid"><%= link_to image_tag("http://img.youtube.com/vi/#{vid.content}/1.jpg"), :controller => 'videos', :action => "iframize", :video_id => vid.id, :method => :post, :remote => true %></div> <% end %>
And I have this in video_controller:
def iframize @video = Video.find(params[:video_id]) respond_to do |format| format.js end end
And this is in the routes:
resource :videos do collection do post 'iframize' end end
The problem is that when I click the link, it takes me to
http:
and i get
Couldn't find Video with id=iframize
I looked through dozens of different examples, and they seem to recommend the above, but that doesn't work. What am I doing wrong?
Any entry is welcome!
Thanks!
EDIT:
I tried this function of the jQuery approach, and it seemed to work (only for the first video in the loop, of course):
<% @node.videos.each do |vid| %> <%= image_tag("http://img.youtube.com/vi/#{vid.content}/1.jpg", :id => 'img_div') %> <div id="vid_vid"> <%= vid.id %></div> <% end %> $('#img_div').on({ 'click': function() { var vid_id = document.getElementById("vid_vid").innerHTML; $.post("/videos/iframize/", {video_id: vid_id}); } });