Sinatra Haml:访问对象属性

发布于 2024-12-02 06:25:48 字数 357 浏览 1 评论 0原文

我是 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技术交流群

发布评论

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

评论(1

独行侠 2024-12-09 06:25:48

如果您使用datamapper(activerecord没有不同):

在控制器中:

get '/' do
  @todos = Todo.all
  haml :todo
end

在视图中:

%ul
  [email protected] do |todo|
    %li
      =todo.title
      %br
      =todo.task

所有事物都是对象,并且在哪里可以访问它的属性没有区别。
你可以这样做:

 ...
 -Todo.all.each do |todo|
 ...

但这不是好方法。

If you use datamapper (activerecord doesn't differ):

in controller:

get '/' do
  @todos = Todo.all
  haml :todo
end

in view:

%ul
  [email protected] do |todo|
    %li
      =todo.title
      %br
      =todo.task

All things is objects and no difference where you can access to it properties.
You can do:

 ...
 -Todo.all.each do |todo|
 ...

but this not good way.

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