Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 关于自定义rails 3脚手架模板_Ruby On Rails_Ruby_Ruby On Rails 3 - Fatal编程技术网

Ruby on rails 关于自定义rails 3脚手架模板

Ruby on rails 关于自定义rails 3脚手架模板,ruby-on-rails,ruby,ruby-on-rails-3,Ruby On Rails,Ruby,Ruby On Rails 3,在默认的index.html.erb模板中,没有显示id、created\u at、updated\u at列 现在我想通过改变模板来显示它们 但是我没有找到元变量,这是原始index.html.erb模板文件代码的一部分,它使用属性显示所有用户定义的列,但没有显示默认列,有人知道如何添加这3列吗 <% for attribute in attributes -%> <div class="field"> <%%= f.label :<%= at

在默认的index.html.erb模板中,没有显示id、created\u at、updated\u at列

现在我想通过改变模板来显示它们 但是我没有找到元变量,这是原始index.html.erb模板文件代码的一部分,它使用
属性
显示所有用户定义的列,但没有显示默认列,有人知道如何添加这3列吗

<% for attribute in attributes -%>
   <div class="field">
    <%%= f.label :<%= attribute.name %> %><br />
    <%%= f.<%= attribute.field_type %> :<%= attribute.name%> %>
  </div>
<% end -%>



您有双重包装的asp样式标记:

Id: <%= object.id %>
Created at: <%= object.created_at %>
Updated at: <%= object.updated_at %>
Id:
创建于:
更新日期:

代码应该按照您的要求显示这3列,或者它们不存在,看看它们是否在数据库表中。

如果我理解您要查找的内容,应该是这3列。 我不在数据库中观察,只是在模型中观察你想要显示的字段,我希望足够了。。。 这是放在循环前面的行,这是id的行

<%%= 'Id: ' + @<%= singular_table_name %>.id.to_s unless @<%= singular_table_name %>.methods.index(:id).nil? %>


此外,我可以说,确实有一种更好的方法来检查字段的存在性,而不是使用索引函数,总体来说,这可能是一种更好的方法,但这是有效的。

使用双重包装,因为我不想执行它,它是一个脚手架模板(针对模板构建模板)