Rails推荐的方法来处理常用的html样板文件

时间:2013-07-12 12:53:21

标签: ruby-on-rails

例如,在下表中,我在我的应用程序中反复使用这些操作,我不太确定如何干它,部分视图或铁路助手(这似乎不适合处理用html片段)...(我正在使用Slim btw)

我希望能够做到这样的事情: = edit_button(路径,'可选显示文本','可选的额外类)

table.grid
    thead
        tr
            th Researcher
            th Email Address
            th Last Activity
            th Activated
            th Failed logins
            th Locked
            th Actions
    tbody
        - @users.each do |user|
            tr
                td
                    = "#{user.first_name} #{user.last_name}"
                td
                    = user.email
                td
                    | About 1 day ago
                td
                    | Yes
                td
                    = user.failed_logins_count
                td
                    | No
                td
                    div.actions
                        a.small.button.edit href=edit_user_path(user)
                            i.general.foundicon-edit
                            | Edit
                        a.small.button.delete href=user_path(user) method='delete' data-confirm='Are you sure?'
                            i.general.foundicon-trash
                            | Delete

1 个答案:

答案 0 :(得分:3)

使用partials是推荐用于干扰视图的方法。请参阅this页面的前几行。