错误的参数数量错误(0表示1)

时间:2009-10-02 10:41:08

标签: ruby-on-rails

我在index.erb.html文件中有表单。 (上传控制器)。 当我调用localhost:3000 / upload /时出现错误的参数数量(0表示1)错误

    <% form_for :picture, :html => { :multipart => true } do |form| %>
 <p>
    <label for="picture_first_name">First name::</label>
    <%= form.text_field :first_name, :size => 20 %>
 </p>
 <p>
    <label for="picture_last_name">Last name:</label>
    <%= form.text_field :last_name, :size => 20 %>
 </p>
 <p>
    <label for="picture_city">City:</label>
    <%= form.select :city, Picture::CITIES, {}, :onchange => remote_function(:url => {:action => "update_universities"}, :with => "'picture[city]='+value") %>
 </p>
 <p>
    <%= render :partial => 'universities' %>
 </p>
 <p>
    <label for="picture_picture">Photo::</label>
    <%= form.file_field :picture, :size => 20 %>
 </p>
 <%= submit_tag "Upload" %>
<% end %>

所以,我有一个渲染函数,因为我使用AJAX来更新第二个选择字段。

   <label for="picture_university">University:</label>
    <%= form.select :university, [] %>

我的应用有什么问题?请帮我解决这个问题!

  

上传#index

中的ArgumentError      

显示   应用程序/视图/上传/ _universities.html.erb   第2行引出的地方:

     

错误的参数数量(0表示1)

     

提取的来源(第2行):

     

1:大学:   2:&lt;%= form.select:university,[]%&gt;

     

模板包含的痕迹:   应用程序/视图/上传/ index.html.erb

     

RAILS_ROOT:/ home / user_admin / myapp   应用程序跟踪|框架跟踪|   完整跟踪

     

/home/user_admin/myapp/app/views/upload/_universities.html.erb:2:in   form' /home/user_admin/myapp/app/views/upload/_universities.html.erb:2:in _ run_erb_app47views47upload47_universities46html46erb_locals_object_universities'   /home/user_admin/myapp/app/views/upload/index.html.erb:15:in   _run_erb_app47views47upload47index46html46erb' /home/user_admin/myapp/app/views/upload/index.html.erb:1:in _ run_erb_app47views47upload47index46html46erb'

1 个答案:

答案 0 :(得分:2)

您需要将form变量传递给您的部分,所以:

<%= render :partial => 'universities', :locals => {:form => form } %>

这应该使表单对象可用于部分。

相关问题