RoR 创建动态“evernote”页面
所以我正在创建一个简单的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
进行分组
hashify 笔记按notebook_id @notes_hash = @user.notes.group_by(&:notebook_id)
,然后在你的笔记本列表中,当单击笔记本链接时,捕获notebook_id并查看你的@notes_hashnotes
= @notes_hash[笔记本.id] || [ ]
您可以使用 jQuery 动态更新第二列。
确保您需要“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.
make sure you require 'json' gem to use .to_json method.