Skip to content

Instantly share code, notes, and snippets.

<div class="topic_holder">
<% @video.topics.uniq.each do |topic| %>
<div class ="topic round">
<%= link_to "#{topic.name}", "#", :class => 'topic_link' %>
<% topicable = Topicable.find_by_video_id_and_topic_id(@video.id, topic.id) %>
<%= link_to "x", topicable_path(topicable.id), :method => :delete, :class => 'topic_delete' %>
</div>
<% end %>
</div>
<%= form_for @video, :url => {:action => "update"}, :remote => true do |f| %>
$("#video_<%= @video.id %>").parent().parent().children(".topic_holder").html('<% @video.topics.uniq.each do |topic| %><div class ="topic"><%= link_to "#{topic.name}", '#', :class => 'topic_link' %><%= link_to "x", @topicable, :method => :delete, :class => 'topic_delete' %></div><% end %>');
$(".edit_video")[0].reset();
def destroy
@topicable = Topicable.find(params[:id])
@topicable.destroy
respond_to do |format|
format.html {redirect_to :back}
end
end
select: function(event, ui) {
var url = $('.edit_video').attr('action');
var val = ui.item.topic.name;
$.ajax({type:"PUT", url:url, data:{video:{topic_names:val}}});
return false;
}
def update
@video = current_user.videos.find(params[:id])
respond_to do |format|
if @video.update_attributes(params[:video])
format.html { redirect_to(@video) }
format.js
else
format.html { render :action => "edit" }
end
<%= link_to "#{(@video.topics.count == 0) ? 'Add descriptive topics so people can find your song!' : 'Edit Topics'}", '#', :id => 'edit_topics_link', :class => 'edit' %>
#{(@video.topics.count == 0) ? 'Add descriptive topics so people can find your song!' : 'Edit Topics'}
$.get('layouts/text.js.erb', function(data) {
$("#edit_topics_link").text(data);
});
$("#edit_topics_link").text((@video.topics.count == 0) ? 'Add descriptive topics so people can find your song!' : 'Edit Topics');
$("#edit_topics_link").text(<%= (@video.topics().count() == 0) ? 'Add descriptive topics so people can find your song!' : 'Edit Topics' %>);