首页 \ 问答 \ Rails脚手架发电机ID(Rails Scaffold Generator ID)

Rails脚手架发电机ID(Rails Scaffold Generator ID)


当我创建这个模型时,有没有办法可以让<%= posts.id %>这样:

<% @posts.each do |post| %>
  <div id="<%= posts.id %>">
    <%= post.title %>       
<% end %>


为这种困惑道歉。 我想说的是,当你生成一个模型时,它是否带有ID?

I used the scaffold generator to generate a title (string) and body (content) so I can create 'posts'.

When I generatored this model, is there a way I can have <%= posts.id %> so:

<% @posts.each do |post| %>
  <div id="<%= posts.id %>">
    <%= post.title %>       
<% end %>


Apologies for the confusion. What I meant to say is when you generate a model, does it come with an ID?

更新时间:2019-12-03 08:13





You are referencing 'posts' which doesn't exist.

@posts is a collection of posts, so there's no id on that either.

Each post will have an id though, so you can do post.id inside that block just as you have post.title (singular)




回调函数在角度js中不起作用?(call back function not working in angular js?)

抱歉..我找到了解决方案。 我定义上面的方法它工作正常。 这意味着任何方法都应该被定义在它被调用的地方之上。因为我是新来的角js没有意识到它。 $scope.get_product = function() { console.log('Block 1'); $http.get("db.php?action=get_products").success(function(data) { console.log(data);

检索记录我的xcdatamodel并过滤它们(retrieve record my xcdatamodel and filter them)

数据存储中不存在瞬态属性,因此您无法在MOC上运行的谓词中使用它们。 您需要将属性设置为非瞬态,或者您需要进行提取然后过滤结果(但在获取后,瞬态将全部为空)。 Transient attributes don't exist in the data store so you can't use them in predicates run on the MOC. Either you need to make the attribute non-transient or you will nee

CSS:元素的大小在Chrome中以一种非常奇怪的方式发生变化(CSS: size of the elements changes in a very strange way in Chrome)

如果你的意思是#inner应该占用#outer的大小,那么, #inner { min-width:100%; } 要么 #inner { width:100%; } If you mean #inner should occupy the size of #outer then, #inner { min-width:100%; } or #inner { width:100%; }

Mac从邮件中提取HTML(Mac to extract HTML from Mail messages)

您将获得具有source属性的原始源 set end of mailContentList to source of selectedMail 但你必须“手动”提取HTML部分。 You get the raw source with the source property set end of mailContentList to source of selectedMail but you have to extract the HTML portion "manually".

在SQLite和Android中使用列作为选择参数(Use a column as a selection Argument in SQLite and Android)

我相信你的问题可能是你可能正在尝试将字符串转换为指定了Integer.parseInt(DocumentEntry.COLUMN_WARN_IN) 的整数 ( 除非DocumentEntry.COLUMN_WARN_IN解析为整数,否则它可能会出现决心警告 ) 此外,您已经省略了第二个参数的包含,因此无法包含并可能导致参数不匹配问题,因为您提供了两个,但只要求使用一个。 我建议使用: - String selection = DocumentEntry.COLUMN_EXPIRED + " <>

PHP在我的根文件夹中的数据库和文件夹中上传(PHP upload in database and folder in my root folder)

你只需要获取文件。 忘记放入目标文件夹使用file_put_contents $target_file = $img_dir . basename($_FILES["image"]["name"]); $imageName = $_FILES["image"]["name"]; $imageData = file_get_contents($_FILES["image"]["tmp_name"]); // Write the contents back to the file file_p

将所有输出放在JavaScript中的while循环中的特定文本框中(Putting all the output in a specific textbox in a while loop in JavaScript)

你可以这样做: 给答案输入一个id: <input id="answerTextBox" type="text" name="ans" disabled> while循环后填充answer文本框: while (x>y) { document.getElementById("answerTextBox").value += ("" + x); x=x+1; } 这将把x和y放在你的答案文本框中。 UPDATE ****** <html> <body> <script type="tex

如何在AsyncTask或Fragment中处理Null?(How to handle Null in AsyncTask or Fragment?)

在onPost()方法中写一个文档检查 if (document!=null){ Elements elementsId = document.select("id"); Elements elementsCheckin = document.select("checkin"); Elements elementsCheckout = document.select("checkout"); Elements ele




  • 根据Woocommerce中的自定义字段计算自定义购物车商品价格(Custom cart item price calculation based on dimentions custom fields in Woocommerce)
  • 分开foreach项目并单独打印(Separate foreach items and print them individually)
  • 写模式管道是否同步?(Is write mode pipe synchronous?)
  • 发现可用的Windows Phone强调色和本地化名称(Discover available Windows Phone accent colors and localized names)
  • 使用多线程和WPF更新集合(Update Collection with multithreading and WPF)
  • 如何在字符串的情况下使用同步?(How should the synchronization be used in case of strings?)
  • 打印唯一的行,比较不超过N个字符(Print unique lines, compare no more than N characters)
  • Javascript / jQuery - 如何调用switch case从另一个函数执行(Javascript/jQuery - how to call a switch case to execute from another function)
  • Hbase超时错误不断发生(Hbase timeout errors keep occuring)
  • 如何在Delphi中更改TabControl中活动TAB的颜色(How to change the color of active TAB in a TabControl, in Delphi)
  • 正则表达式:在sublime文本中替换一些PHP代码(Regex: replace some pieces of php code in sublime text)
  • 在带有Scene2D的LibGDX中,如何在按下按钮时连续向右走?(In LibGDX with Scene2D, how can I continuously walk to the right when a button is pressed?)
  • 累加器如何在Haskell中工作?(How do accumulators work in Haskell?)
  • 使用开关检查市场和前缀与正确的货币符号(using switch to check market and prefix with correct currency symbol)
  • 在哪里分配一次使用类?(Where to allocate one time use class?)
  • 如何从两个DateTime / NaiveDateTime获取持续时间?(How do I get Duration from two DateTime / NaiveDateTime?)
  • 解析TimeSpan大于24小时?(Parse a TimeSpan greater than 24 hours? [duplicate])
  • 如何在球拍中本地更改阅读规则?(How to locally change reading rules in racket?)
  • 数据库应该由DI注入时的模拟存储(通过构造函数)(Mock storage when database should be injected by DI (through constructor))
  • 使用maven集成2个eclipse项目(Integrate 2 eclipse projects using maven)
  • 角度ng-repeat不检测变化(Angular ng-repeat not detecting changes)
  • Xaml组件在Silverlight + XNA应用程序的多个页面中可见(Xaml component visible in multiple pages in Silverlight+XNA applications)
  • 如何将`var`变量等同于另一个查询(How to equate `var` variable to another query)
  • 如何设计hyperledger链代码以适合您的业务?(how to design your chaincode of hyperledger to fit for your business?)
  • PHP readfile错误(PHP readfile error)
  • 在Date之后排序列表然后是时间(Sorting list after Date then time)
  • Android内部版本号(Android build number)
  • 在没有预设退出条件的情况下停止无限循环(stopping an infinite loop with no preset exit condition)
  • Phonegap应用程序全屏通过html页面中的按钮(Phonegap Application fullscreen through a button in html page)
  • PAA是否适合在门户网站中自动执行wcm库部署和设置?(Is PAA a good candidate for automating wcm library deployment and setup in portal?)