[英]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.