I want to connect two entity (project and issues) and Rails says some error message, but I don't know, what should I do. Can you help me fix it, please? Thanks a lot.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Not sure what your are trying to do, but it looks like you have a nested resource and therefore want to pass an array to form_for
, but you are actually passing two separate objects. Change:
<%= form_for(@project, @project.issues.build) do |f| %>
to:
<%= form_for([@project, @project.issues.build]) do |f| %>
With this change you'll pass one array for form_for
, instead of two arguments.
回答2:
I think you have used nested resources like this:
resources projects do
resources issues
end
If you used that, try make your form like this:
<%= form_for([@project, @issue]) do |f| %>
and in your IssueController :
def new
@project = Project.new
@issue = @project.issues.build(params[:issue])
end
def create
@project = Project.find(params[:project_id]
@issue = @project.issues.create(params[:issue]
end
and run again to see something happen. Hope this help.