简体   繁体   English

Ruby on Rails和石工问题

[英]Ruby on Rails and Masonry problems

I'm having some troubles implementing Masonry in my RoR project. 我在RoR项目中实施砌筑时遇到了一些麻烦。

I think I can explain it better with the current web page: http://sttorybox.herokuapp.com/ 我想我可以用当前网页更好地解释它: http : //sttorybox.herokuapp.com/

As you can see, if you open the page, masonry is working fine. 如您所见,如果打开页面,则砖石工作正常。 But, for example, you go into a story individual page (you must be logged in-> user:test@test.com , pass:test), clicking on title in the box (first box, it was created by test user), and now click in the title of the page: STTORYBOX in the top bar masonry now is not working and I don't know why :/ 但是,例如,您进入一个故事个人页面(您必须登录-> user:test@test.com,pass:test),单击框中的标题(第一个框,它是由测试用户创建的) ,然后单击页面标题:顶部钢筋中的STTORYBOX现在不起作用,我也不知道为什么:/

Here is my JS code: 这是我的JS代码:

$(function() {
  var options = {
    itemSelector: ".item",
    isAnimated: true,
    layoutPriorities:{
      upperPosition: 1,
      shelfOrder: 1
    }
  }

  $container = $("#items").masonry(options);
});

I hope you guys can help me. 我希望你们能帮助我。 Thanks in advance. 提前致谢。

I solved the issue, the problem was some behaviour of turbolink rails gem. 我解决了这个问题,问题是turbolink rails gem的某些行为。

The solution was to add all my content as a anonymous function like that: 解决方案是将我所有的内容添加为这样的匿名函数:

var content = function() {
    ... content ...
};

And later using turbolinks function page:load in order to execute my code again 然后使用turbolinks函数page:load再次执行我的代码

$(document).on('page:load', content);

Also I had to add this regular jquery function to load my content too: 另外我还必须添加此常规jquery函数来加载我的内容:

$(document).ready(content);

I hope this help some people. 希望这对某些人有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM