2

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'

2
  • 1
    As far as I can tell from your views the variable form is not known inside your universities view, but this would result in another error. You should provide the complete error trace for more detail. Commented Oct 2, 2009 at 11:39
  • Koraktor, please help. I've just added the complete error trace. Commented Oct 2, 2009 at 12:35

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

2 Comments

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.