Sinatra Haml:访问对象属性
我是 sinatra 和 haml 的新手。我正在编写一个简单的待办事项应用程序。 在控制器中,我正在创建一个待办事项对象列表。例如,每个待办事项都有属性“标题”和“优先级”。待办事项列表是 sinatra 控制器的一个属性(@todos = .. 待办事项列表)
我可以访问/迭代待办事项列表
%ul
- @todos.each do |todo|
%li= todo ....
等等。
但是我如何访问我的待办事项对象的属性(“标题”,“优先级”)? 其语法是什么? 尝试了几个但没有找到合适的..
你能帮助我吗?
I´m new to sinatra and haml. I am writing a simple todo application.
In the controller I am creating a list of todo-Objects. Every todo has for example the attributes "title" and "priority". The list of todos is an attribute of the sinatra controller (@todos = .. list of todo objects)
I can access/iterate the list of todos with
%ul
- @todos.each do |todo|
%li= todo ....
and so on.
But how can I access the attributes of my todo-objects ("title", "priority") ?
What is the syntax for that?
Tried several but didn´t find the right one..
Can you help me?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您使用datamapper(activerecord没有不同):
在控制器中:
在视图中:
所有事物都是对象,并且在哪里可以访问它的属性没有区别。
你可以这样做:
但这不是好方法。
If you use datamapper (activerecord doesn't differ):
in controller:
in view:
All things is objects and no difference where you can access to it properties.
You can do:
but this not good way.