简体   繁体   English

Rails 5:使用link_来定位mp3(作为模型对象)以及具有相同对象不同属性的单独div吗?

[英]Rails 5: use link_to target an mp3 (as a model object) as well as a separate div with a different attribute of the same object?

This is a bit complicated. 这有点复杂。 Not sure if it's even possible. 不知道是否有可能。 I'll try to explain as best as possible, just ask if something seems confusing. 我会尝试尽可能最好地进行解释,只是问一下是否有些令人困惑。

I am designing a page for a band's album. 我正在为乐队的专辑设计页面。 The mp3s are uploaded to an S3 bucket and are also saved in the RoR database as a model object. mp3上载到S3存储桶,并且也作为模型对象保存在RoR数据库中。 The model attributes include: title and lyrics. 模型属性包括:标题和歌词。

I'm designing the site with three Bootstrap columns. 我正在设计带有三个Bootstrap列的站点。 The left one holds the track list with all of the songs looped and linked to a jQuery mp3 player when one is clicked. 左侧的曲目保存曲目列表,单击时会循环播放所有歌曲并将其链接到jQuery mp3播放器。 The middle column holds the album's cover. 中间一栏是专辑的封面。 For the right column, I'd like to be able to display the lyrics for the song that was most recently clicked, but I am puzzled as to how to go about this. 对于右列,我希望能够显示最近被点击的歌曲的歌词,但是我对如何执行此操作感到困惑。

I have tried using simple jQuery script and css to hide the div's display then change it to a block or inline display on click. 我尝试使用简单的jQuery脚本和CSS来隐藏div的显示,然后在单击时将其更改为块或嵌入式显示。 This either showed all of the lyrics for every song, or else didn't work at all. 这要么显示每首歌曲的所有歌词,要么根本不起作用。 I also toyed with the idea of targeting the divs with a link anchor, but I can't figure out how to implement that along with the mp3 in the same link. 我也想过使用链接锚定位div的想法,但是我不知道如何在同一链接中将其与mp3一起实现。 I suppose I could completely redesign the layout by removing the grid system and using floats and the like, but I'd prefer to avoid that if at all possible. 我想我可以通过删除网格系统并使用浮点数等来完全重新设计布局,但我希望尽可能避免这种情况。

Can anyone think of a solution? 谁能想到解决方案? I'm quite puzzled as to how this should work. 我对这应该如何工作感到很困惑。 Or should I scrap the idea altogether? 还是我应该完全放弃这个主意?

Here is my current relevant code: 这是我当前的相关代码:

<div class="container-fluid">
  <div class="row">
    <div class="col-md-4 tracklist">
      <div id="sm2-container">
        <!-- SM2 flash goes here -->
      </div>
      <ul class="playlist">
      <% @album.songs.sort { |a,b| a.track <=> b.track }.each do |s| %>
        <li class="track-num">
          <%= link_to(s.audio.url) do %>
            <%= s.title %>
          <% end %>
        </li>
      <% end %>
      </ul>
    </div>
    <div class="col-md-4">
      <%= image_tag(@album.image.url, :class => 'album-cover') %>
    </div>
    <div class="col-md-4">
      <div class="row">

        <!-- I would like the following div to display the lyrics of the 
             most recently clicked song from the above div ('.playlist'): -->

        <div class="track-lyrics">
            <%= simple_format(@song.lyrics) %>
        </div>
      </div>
    </div>

  </div>
</div>

Hopefully this isn't too confusing. 希望这不会太令人困惑。 I thought some basic javascript would do the trick, but I'm starting to wonder if it's possible at all. 我以为可以使用一些基本的javascript来解决问题,但我开始怀疑是否有可能。 Or perhaps it needs to go into more advanced script. 也许它需要进入更高级的脚本。 Perhaps it's as simple as creating a helper method and I'm not just seeing the clues. 也许就像创建一个辅助方法一样简单,而我不仅看到了线索。

Dynamically put the song id inside the Div class. 动态地将歌曲ID放入Div类中。

Div class = "<%= song.id %> " Div class =“ <%= song.id%>”

Hide all of them by default. 默认情况下隐藏所有这些。 Show when that song id is selected. 在选择该歌曲ID时显示。

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

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