简体   繁体   English

如何将ID从一张桌子存储到另一张桌子上的红宝石在Rails 2上

[英]How to store the id from the one table to another in ruby on rails 2

Hello i'm trying to make a simple review function on ruby on rails. 您好,我正在尝试在Rails上做一个简单的评论功能。 i have create a scaffold with the following attributes 我创建了一个具有以下属性的脚手架

event_id:integer name:string review_text:text no_starts:integer event_id:整数名称:字符串review_text:文本no_starts:整数

Then i made this change on the show (view) of my event 然后,我在活动的节目(视图)上进行了更改

:review, :action => :new, :id => @event.id %> :review,:action =>:new,:id => @ event.id%>

now i configured the routes fine and on the controller of the review i made this changes. 现在,我配置了路由,并在检查的控制器上进行了更改。 on the new i have added this 在新的我已经添加了这个

@review = Review.new(:event_id => params[:id]) and removed this @review = Review.new @review = Review.new(:event_id => params [:id])并删除了此@review = Review.new

Then the page loads the event id it cites on the page but when i'm trying to save it is not stored. 然后页面加载它在页面上引用的事件ID,但是当我尝试保存时未存储。 i thing the problem is when i move from the new method to create it doesnt transfer the id of the event thats why but i'm still what i'm doing wrong in the new? 我的问题是,当我从新方法转移到创建方法时,它不会传输事件ID,这就是为什么,但是我仍然在新方法中做错什么吗?

Does :event_id is accessible in your Review modul? :event_id是否可以在您的评论模块中访问? Actually that would be better if not, but unless it is, then it won't work. 实际上,如果不是这样的话,那会更好,但是除非如此,否则它将无法正常工作。

Try using this instead: 尝试使用此代替:

@event = Event.find(params[:id])
@review = @event.build_review

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

相关问题 Ruby on Rails和Devise将一个表中的ID关联到另一个表中的foreign_key ID - Ruby on Rails and Devise associating id from one table to a foreign_key id in another table 将数据从一个表存储到另一个表中 - Store data from one table to another in rails 将数据从一张桌子添加到另一张桌子上的红宝石 - Add data from one table to another in ruby on rails Ruby on Rails:如何通过用户界面中的按钮将特定/选择的记录从一个表(用户)发送到另一个表 - Ruby on Rails: How to send a specific/chosen record from one table (User) to another with a button from user interface 将用户标识存储到另一个表中作为ruby on rails上的外键的基本规则 - Basic rule to store User ID into another table as foreign key in ruby on rails 用于将数据从一个表存储到另一个表的按钮 - Button to store data from one table to another in rails 如何从rails上的ruby中的另一个表字段更新表字段 - How to update table fields from another table fields in ruby on rails 如何从控制器Ruby On Rails中传递表中的用户ID - How to pass user id in table from controller Ruby On Rails Ruby on Rails-通过另一个控制器传递ID - Ruby on Rails - Pass ID from another controller 如何从另一个表栏中的 id 到达表的列 - How to reach a table's column from an id in another table rails
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM