I need your help to plan my Idea.
我需要你的帮助来计划我的想法。
First I show you what I want to release:
![enter image description here][1]
There is a html-table which should have a content as above (Header-Date, title, time, location). As you can see, it's a schedule.
首先,我向您展示我想要发布的内容:![在此处输入图像描述] [1]有一个html表,其中应包含上述内容(标题日期,标题,时间,位置)。如您所见,这是一个时间表。
Model:
There is a user-model, which contains a schedule-column as an array, because I dont want to use the relationship behavior. So I just want to save the schedule-model-name in this array.
Furthermore there is a schedule-model, which contains date, title, time, location and a user-array for the access.
模型:有一个用户模型,它包含一个schedule-column作为数组,因为我不想使用关系行为。所以我只想在这个数组中保存schedule-model-name。此外,还有一个计划模型,其中包含日期,标题,时间,位置和访问的用户阵列。
MESSAGE to the RoR-experts: Thanks for the belongs_to
-suggestion, BUT I dont get it and I have to explain my decision at my oral exam, so that I just want to use, what I really understand.
对RoR专家的致辞:感谢belongs_to-suggestion,但我得不到它,我必须在口语考试中解释我的决定,所以我只想用,我真正理解。
Controller:
Handles the access to the schedule-model, e.g. @all
.
I think that won't any problem to me.
控制器:处理对计划模型的访问,例如@所有。我认为这对我没有任何问题。
View:
This is the point, where I need your help.
I googled something like "dynamic table content" and found this:
[Generate an HTML table from an array of hashes in Ruby][2], BUT I don't really understand any of their answers..
观点:这是我需要你帮助的地方。我搜索了类似“动态表格内容”的内容,发现:[从Ruby中的哈希数组中生成一个HTML表格] [2],但我真的不明白他们的任何答案。
During typing this question, I realised that I should do more than @all
in the Controller.
It's also important to have more than one appointment at a day.
If the time is similar or the same the appointments should shown in parallel.
If the time isn't similar the appointments should shown among themselves. (this isnt shown in the picture)
在输入这个问题时,我意识到我应该做的不仅仅是@allin Controller。一天进行多次预约也很重要。如果时间相似或相同,则约会应平行显示。如果时间不相似,则约会应相互显示。 (图中未显示)
I also hope that there is someone who'll take his time to help.
我也希望有人能抽出时间帮忙。
1 个解决方案
#1
0
You'd be best setting it up like this:
你最好这样设置:
#app/models/user.rb
Class User < ActiveRecord::Base
has_many :schedules
end
#app/models/schedule.rb
Class Schedule < ActiveRecord::Base
belongs_to :user
end
Then your tables could be constructed as such:
那么你的表可以这样构造:
#schedules
id | user_id | titel | location | time | created_at | updated_at
This means that you can do this:
这意味着你可以这样做:
#config/routes.rb
resources :users, only: :index
#app/controllers/users_controller.rb
def index
@schedules = current_user.schedules
end
#app/views/users/index.html.erb
<%= for schedule in @schedules do %>
<strong><%= schedule.titel %></strong>
<%= schedule.time %>
<%= schedule.location %>
<% end %>
This will output a list of schedules / appointments for your user. In order to get the grouped effect, you'll have to use the likes of group_by
in your controller
这将输出您的用户的计划/约会列表。为了获得分组效果,您必须在控制器中使用group_by
#1
0
You'd be best setting it up like this:
你最好这样设置:
#app/models/user.rb
Class User < ActiveRecord::Base
has_many :schedules
end
#app/models/schedule.rb
Class Schedule < ActiveRecord::Base
belongs_to :user
end
Then your tables could be constructed as such:
那么你的表可以这样构造:
#schedules
id | user_id | titel | location | time | created_at | updated_at
This means that you can do this:
这意味着你可以这样做:
#config/routes.rb
resources :users, only: :index
#app/controllers/users_controller.rb
def index
@schedules = current_user.schedules
end
#app/views/users/index.html.erb
<%= for schedule in @schedules do %>
<strong><%= schedule.titel %></strong>
<%= schedule.time %>
<%= schedule.location %>
<% end %>
This will output a list of schedules / appointments for your user. In order to get the grouped effect, you'll have to use the likes of group_by
in your controller
这将输出您的用户的计划/约会列表。为了获得分组效果,您必须在控制器中使用group_by