简体   繁体   English

Rails推荐的方式来处理常用的HTML样板

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

For instance, in the table below, I am using the actions over and over throughout my app, and I am not quite sure how to DRY it up, either partial views or rails helpers (which don't seem great for dealing with html fragments)...(I am using Slim btw) 例如,在下表中,我在整个应用程序中反复使用动作,但我不确定如何将其干燥,无论是局部视图还是Rails帮助器(对于处理html片段似乎都不是很好) )...(我正在使用Slim btw)

I would like to be able to do something like: = edit_button (path, 'optional display text', 'optional extra classes) 我希望能够执行以下操作:= 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

Using partials are the rails recommended way to DRY up your view. 建议使用局部函数来干燥视图。 See the first few lines of this page. 请参阅页面的前几行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在Rails应用程序中获取和查看常用数据的最有效方法是什么? - What is the most effecient way to get and view commonly used data inside a Rails application? rails中的一个常用方法好在哪里... - Where is a good place for a commonly used method... in rails Rails常用字符串(用于通知和错误消息等) - Rails commonly used strings (for notices and error messages and the like) 在Rails中查找记录的推荐方法 - Recommended way to find a record in rails 对于Rails应用程序,HTML5 Boilerplate的价值是多少? - What is the value of HTML5 Boilerplate for a Rails application? Rails 4处理过滤器的方式是什么? - What is the Rails 4 way to deal with filters? 有推荐的方法来处理Rails中的Twitter API错误吗? - Is there recommended way to handle Twitter API error in rails? Rails建议添加样本数据的方法 - Rails recommended way to add sample data 生产模式:在数据库中更改和添加数据的“最佳方法”是什么?“最常用的方法”? - Production mode: what is “the best way”\“the most commonly used approach” to change and add data in database? Rails:STI处理实体子类型的最佳方法? - Rails: STI best way to deal with entity subtypes?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM