开发者

Sinatra Haml: Access object attributes

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 t开发者_运维问答he 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?


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

in controller:

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

in view:

%ul
  -@todos.each 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜