[英]How to change the newly created default view on Rails
Every time I use scaffold
to generate related files. 每次我使用
scaffold
生成相关文件时。
I have to modify the *.html.erb
to *.html.haml
and change the content to my preference layout. 我必须将
*.html.erb
修改为*.html.haml
,并将内容更改为我的首选项布局。
Is there any better practice to achieve this ? 有没有更好的做法来实现这一目标?
Thanks. 谢谢。
For example, I have the these columns in my model :excel, :model, :result_file, :user_id, :version, :xml
. 例如,我的模型中有这些列
:excel, :model, :result_file, :user_id, :version, :xml
。
I omit the default index.html.erb
file (the scaffold
generated it for me). 我省略了默认的
index.html.erb
文件( scaffold
为我生成了该文件)。
and I will change the index.html.erb
in my custom default layout. 然后我将在自定义默认布局中更改
index.html.erb
。
I'd rather every time the scaffold will generate this pattern for me. 我宁愿每次脚手架都会为我生成这种模式。
I know I can modified the template file under my .rvm
我知道我可以在
.rvm
下修改模板文件
~/.rvm/gems/ruby-1.9.3-p448/gems/railties-3.2.13/lib/rails/generators/erb/scaffold
But is it a good practice ? 但这是一个好习惯吗?
%h1 ND
%div{:class => "hero-unit"}
%large
使用前請先安裝 Firefox plugin
%h2.center
= link_to "新增一筆測試", new_nd_multi_lang_path, |
:class=> "btn btn-primary autotest"
%table#rf_tbl.table.table-condensed.table-striped
%tr
%th Date
%th User
%th Model
%th Version
%th Excel
%th Xml
%th Result file
%th
%th
%th
- @nd_multi_langs.each do |nd_multi_lang|
%tr.center
%td= nd_multi_lang.created_at.strftime("%Y-%m-%d %H:%M")
%td= nd_multi_lang.user.email
%td= nd_multi_lang.model
%td= nd_multi_lang.version
%td
= link_to 'Excel', nd_multi_lang.excel.to_s
%td
= link_to 'XML', nd_multi_lang.xml.to_s
%td
= link_to 'Download', nd_multi_lang.result_file.to_s, :class=> "btn btn-info"
%br/
Using the gem for haml-rails, should do that by default. 将gem用于haml-rails,默认情况下应该这样做。
You editted your question to ask something entirely different >.< 您已编辑问题,以提出完全不同的问题>。<
Here is a guide to answer to your new question. 这是回答新问题的指南。
http://guides.rubyonrails.org/generators.html#customizing-your-workflow-by-changing-generators-templates http://guides.rubyonrails.org/generators.html#customizing-your-workflow-by-changing-generators-templates
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.