簡體   English   中英

Rails推薦的方式來處理常用的HTML樣板

[英]Rails recommended way to deal with commonly used html boilerplate

例如,在下表中,我在整個應用程序中反復使用動作,但我不確定如何將其干燥,無論是局部視圖還是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

建議使用局部函數來干燥視圖。 請參閱頁面的前幾行。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM