ArgumentError in Rails

拥有回忆 提交于 2019-12-24 06:55:28

问题


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.



来源:https://stackoverflow.com/questions/13195737/argumenterror-in-rails

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!