views:

684

answers:

1

I have the form in index.erb.html file. (upload controller). When i call localhost:3000/upload/ an error appeares wrong number of arguments (0 for 1) error

    <% 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 %>

So, I have a render function, because i use AJAX to update the second select field.

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

What is the problem with my app? Please help me to fix that!

ArgumentError in Upload#index

Showing app/views/upload/_universities.html.erb where line #2 raised:

wrong number of arguments (0 for 1)

Extracted source (around line #2):

1: University: 2: <%= form.select :university, [] %>

Trace of template inclusion: app/views/upload/index.html.erb

RAILS_ROOT: /home/user_admin/myapp Application Trace | Framework Trace | Full Trace

/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  A: 

You need to pass the form variable through to your partial, so:

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

this should make the form object available to your partial.

Lolindrath
Lolindrath, thank u very,very much!!! I'm happy now.But I still can't understand why I need to do that. I SEE that RAILS framework is very pointed and difficult.
Anton
The reason this happens is because you are moving into a different ruby file which changes your variable scope.There are a few quirky things you have to deal with in Rails but generally the shear velocity that Rails lets you develop at is staggering.
Lolindrath