【问题标题】:RoR creating a dynamic "evernote"-ish pageRoR 创建一个动态的“evernote”页面
【发布时间】:2012-01-03 19:54:21
【问题描述】:

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

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 动态更新它们......但我仍然没有弄清楚如何去做。

很抱歉听起来很新手。

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

http://i.stack.imgur.com/8gs0l.png

感谢您的宝贵时间!

【问题讨论】:

    标签: javascript jquery ruby-on-rails ruby evernote


    【解决方案1】:

    散列笔记以按 notebook_id 分组

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

    然后在你的笔记本列表中,当点击笔记本链接时,抓住 notebook_id 并查看你的 @notes_hash

    notes = @notes_hash[notebook.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 方法。

    【讨论】:

      猜你喜欢
      • 2020-01-21
      • 2013-01-29
      • 2018-03-21
      • 2016-01-16
      • 1970-01-01
      • 2015-01-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多