当我点击分享链接但我没有打开时,我正试图加载弹出窗口我不知道我在哪里弄错了
我正在按照本教程进行第12步
[http://code.tutsplus.com/tutorials/build-a-dropbox-like-file-sharing-site-with-ruby-on-rails--net-17940]
[index.html.erb]
<% unless user_signed_in? %>
<h1>Welcome to ShareBox</h1>
<p>File sharing web application you can't ignore.</p>
<% else %>
<div id="menu">
<ul id= "top_menu">
<% if @current_folder %>
<li><%= link_to "Upload", new_sub_file_path(@current_folder) %></li>
<li><%= link_to "New Folder", new_sub_folder_path(@current_folder) %></li>
<% else %>
<li><%= link_to "Upload", new_asset_path %></li>
<li><%= link_to "New Folder", new_folder_path %></li>
<% end %>
</ul>
</div>
<%= render :partial => "breadcrumbs" %>
<div class="asset_list_header">
<div class="file_name_header">File Name</div>
<div class="file_size_header">Size</div>
<div class="file_last_updated_header">Modified</div>
</div>
<div class="asset_list">
<!-- Listing Folders -->
<% @folders.each do |folder| %>
<div class="asset_details folder">
<div class="file_name"><%= link_to folder.name, browse_path(folder) %></div>
<div class="file_size">-</div>
<div class="file_last_updated">-</div>
<div class="action">
<div class="share">
<div id="open">
<%= link_to "Share" ,"#", :folder_id => folder.id, :folder_name => folder.name %>
</div>
</div>
<div class="rename">
<%= link_to "Rename", rename_folder_path(folder) %>
</div>
<div class="delete">
<%= button_to 'destroy', folder_path(folder), :confirm => 'Are you sure to delete the folder and all of its contents?', :method=>:delete %>
</div>
</div>
</div>
<% end %>
<!-- listing files -->
<% @assets.each do |asset| %>
<div class="asset_details file">
<div class="file_name"><%= link_to asset.file_name, download_url(asset) %></div>
<div class="file_size"><%= number_to_human_size(asset.file_size, :precision => 2) %></div>
<div class="file_last_updated"><%= asset.uploaded_file_updated_at %></div>
<div class="action">
<div class="download">
<%= link_to "Download" ,download_url(asset) %>
</div>
<div class="delete">
<%= button_to 'destroy', folder_path(asset), :confirm => 'Are you sure to delete the folder and all of its contents?', :method=>:delete %>
</div>
</div>
</div>
<% end %>
</div>
<div id="invitation_form" title="Invite others to share" style="display:none">
<% form_tag '/home/share' do -%>
<label for="email_addresses">Enter recipient email addresses here</label><br />
<%= text_field_tag 'email_addresses', "", :class => 'text ui-widget-content ui-corner-all'%>
<br /><br />
<label for="message">Optional message</label><br />
<%= text_area_tag 'message',"", :class => 'text ui-widget-content ui-corner-all'%>
<%= hidden_field_tag "folder_id" %>
<% end -%>
</div>
<% end %>
[家庭控制器]
class HomeController < ApplicationController
def index
if user_signed_in?
@folders = current_user.folders.roots
@assets = current_user.assets.where("folder_id is NULL").order("uploaded_file_file_name desc")
end
end
def browse
#get the folders owned/created by the current_user
@current_folder = current_user.folders.find_by_id(params[:folder_id])
if @current_folder
#getting the folders which are inside this @current_folder
@folders = @current_folder.children
#We need to fix this to show files under a specific folder if we are viewing that folder
@assets = current_user.assets.order("uploaded_file_file_name desc")
render :action => "index"
else
flash[:error] = "You cannot acces other ppl folder"
redirect_to root_url
end
end
end
[的application.js]
$(function () {
//open the invitation form when a share button is clicked
$( ".share a" )
.button()
.click(function() {
//assign this specific Share link element into a variable called "a"
var a = this;
//First, set the title of the Dialog box to display the folder name
$("#invitation_form").attr("title", "Share '" + $(a).attr("folder_name") + "' with others" );
//a hack to display the different folder names correctly
$("#ui-dialog-title-invitation_form").text("Share '" + $(a).attr("folder_name") + "' with others");
//then put the folder_id of the Share link into the hidden field "folder_id" of the invite form
$("#folder_id").val($(a).attr("folder_id"));
//the dialog box customization
$( "#invitation_form" ).dialog({
height: 300,
width: 600,
modal: true,
buttons: {
//First button
"Share": function() {
//get the url to post the form data to
var post_url = $("#invitation_form form").attr("action");
//serialize the form data and post it the url with ajax
$.post(post_url,$("#invitation_form form").serialize(), null, "script");
return false;
},
//Second button
Cancel: function() {
$( this ).dialog( "close" );
}
},
close: function() {
}
});
return false;
});
});
答案 0 :(得分:0)
我认为你实现点击事件的方式是错误的。考虑将其更改为
$( "body" ).on("click", ".share a", function() {...
如果你异步加载内容,那么默认.click事件将不起作用,你必须使用.on方法绑定事件来控制你异步生成
答案 1 :(得分:0)
使用以下代码:
$( "body" ).on("click", ".share a", function() {...code...});
我希望它可以帮助您解决问题。
答案 2 :(得分:0)
<script src="/pipeline_assets/jquery.self-a714331225dda820228db323939889f149aec0127aeb06255646b616ba1ca419.js?body=1"></script>
<script src="/pipeline_assets/jquery_ujs.self-d456baa54c1fa6be2ec3711f0a72ddf7a5b2f34a6b4f515f33767d6207b7d4b3.js?body=1"></script>
<script src="/pipeline_assets/turbolinks.self-c37727e9bd6b2735da5c311aa83fead54ed0be6cc8bd9a65309e9c5abe2cbfff.js?body=1"></script>
<script src="/pipeline_assets/assets.self-877aef30ae1b040ab8a3aba4e3e309a11d7f2612f44dde450b5c157aa5f95c05.js?body=1"></script>
<script src="/pipeline_assets/controls.self-ab2e2fa469e30fcd7a69ff0fdf510bf7fd037396e9fb3e77c84af11b60aff548.js?body=1"></script>
<script src="/pipeline_assets/dragdrop.self-36431046ae5f9e21ecda6df33f8c0c4eb27662780cef6fca6f29c93ce550e00b.js?body=1"></script>
<script src="/pipeline_assets/effects.self-dd03ea45ac506c542f4130304d3f8a78ebcd0a10996add7a0896665d0a1a7346.js?body=1"></script>
<script src="/pipeline_assets/folders.self-877aef30ae1b040ab8a3aba4e3e309a11d7f2612f44dde450b5c157aa5f95c05.js?body=1"></script>
<script src="/pipeline_assets/jquery-1.4.4.min.self-4f26ef985d523b47553f38a0e8ff3084dbeb3d177a1df62ccf650ecd288d2c8f.js?body=1"></script>
<script src="/pipeline_assets/jquery-ui-1.8.9.custom.min.self-7ca2e56d842202968964bce8796efe4b122f989de0e317e9a8815a3721e36547.js?body=1"></script>
<script src="/pipeline_assets/jquery.rails.self-b53727dd8652853e07923b1d5c99755df923482448e4e0f869b988f51af34af0.js?body=1"></script>
<script src="/pipeline_assets/prototype.self-a25a23744532b0eed575efd9fe88f42d7f042ed73e3abdb0911748b63e217d5c.js?body=1"></script>
<script src="/pipeline_assets/rails.self-7fa7e1dfd72cae11fff2095dd6171afc6fafbfb76f4668873445883a71287dcc.js?body=1"></script>
<script src="/pipeline_assets/scriptaculous.self-6845f707fc3579647bbe9b48f10a86c8edc7a7f564af9a7465832a2577ec1fdd.js?body=1"></script>
<script src="/pipeline_assets/users.self-877aef30ae1b040ab8a3aba4e3e309a11d7f2612f44dde450b5c157aa5f95c05.js?body=1"></script>
<script src="/pipeline_assets/social-share-button.self-d1725d35699d974c9834cae2be205aae782d1dc63fe9d4cebcfce8146bf2e71a.js?body=1"></script>
<script src="/pipeline_assets/application.self-29d8065068110d1c25667fc41416f8a3216af60ecde3cb52fe0095c720578d84.js?body=1"></script>
答案 3 :(得分:0)
您似乎必须将班级分享更改为
$( ".share a" )
到
$( "#open a" )
或者,如果您认为div open
不需要,则可以将其删除,因为教程中没有任何内容。
<div class="share">
<%= link_to "Share" ,"#", :folder_id => folder.id, :folder_name => folder.name %>
</div>
我希望这对你有所帮助。