RoR 创建动态“evernote”页面

发布于 2024-12-17 16:14:30 字数 961 浏览 3 评论 0原文

所以我正在创建一个简单的 RoR 应用程序,具有 Evernote 的外观和感觉。

notebook.rb

class Notebook < ActiveRecord::Base
  belongs_to :user
  has_many :notes
end

note.rb

class Note < ActiveRecord::Base
  belongs_to :user
  belongs_to :notebook
end

我继续创建了一个带有索引视图的静态控制器,这将是我显示仪表板的地方

static_controller.rb

class StaticController < ApplicationController
  def index
    if user_signed_in?
      @user = current_User
      @notebooks = @user.notebooks
      @notes = @user.notes
    end
  end
end

我应该如何显示笔记本列表?每当用户单击特定笔记本时,该笔记本的笔记就会显示在第二列中...

我正在考虑为此创建 iframe,但如果这些都是 div,并且我们可以使用 jquery 来更新它们,那就更好了动态...但我仍然不知道该怎么做。

抱歉,听起来很新手。

这是我基本上想要完成的任务的快照

https://i.sstatic.net/8gs0l.png

谢谢您的宝贵时间!

so i'm creating a simple RoR app with an evernote look and feel.

notebook.rb

class Notebook < ActiveRecord::Base
  belongs_to :user
  has_many :notes
end

note.rb

class Note < ActiveRecord::Base
  belongs_to :user
  belongs_to :notebook
end

And i went ahead and created a static controller with an index view, this will be where I display the dashboard

static_controller.rb

class StaticController < ApplicationController
  def index
    if user_signed_in?
      @user = current_User
      @notebooks = @user.notebooks
      @notes = @user.notes
    end
  end
end

How should I display the list of notebooks? and whenever the user clicks a specific notebook, that notebook's notes gets displayed in the second column...

I'm thinking of creating iframes for this, but it would be better if these were all divs and we can just use jquery to update them dynamically... but I still haven't figured out how to do it.

Sorry to sound very newbie-ish.

Here's a snapshot of what I basically want to accomplish

https://i.sstatic.net/8gs0l.png

Thank you for your time!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

你与清晨阳光 2024-12-24 16:14:30

进行分组

hashify 笔记按notebook_id @notes_hash = @user.notes.group_by(&:notebook_id)

,然后在你的笔记本列表中,当单击笔记本链接时,捕获notebook_id并查看你的@notes_hashnotes

= @notes_hash[笔记本.id] || [ ]

您可以使用 jQuery 动态更新第二列。

<script type="text/javascript">
  var notes = <%= notes.collect{|a| a.note_content }.to_json %>;

  /* 
   * do stuff here with your array of notes content
   *
   */

</script>

确保您需要“json”gem 才能使用 .to_json 方法。

hashify notes to group it by notebook_id

@notes_hash = @user.notes.group_by(&:notebook_id)

then on you notebook list, when the notebook link is clicked, catch the notebook_id and just look into your @notes_hash

notes = @notes_hash[notebook.id] || [ ]

you can use jQuery to dynamically update your second column.

<script type="text/javascript">
  var notes = <%= notes.collect{|a| a.note_content }.to_json %>;

  /* 
   * do stuff here with your array of notes content
   *
   */

</script>

make sure you require 'json' gem to use .to_json method.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文