title: undefined method `name' for nil:NilClass when trying to upload file into database using ruby on rails
body: <p>i am new to both ruby on rails and stackoverflow, so i hope i am doing this right.</p>
  
  <p>i am trying to write a form to upload files into database using rails and i am getting this error:</p>
  
  <pre><code>ActiveRecord::StatementInvalid in ConfsController#create
  NoMethodError: undefined method `name' for nil:NilClass: INSERT INTO "confs
  ("control_unit_brand", "control_unit_model", "created_at", "description", "developer_id",
  "linear_axis_number", "machine_brand", "machine_model", "milling_mode",
  "rotary_axis_number", "tool_axis_x", "tool_axis_y", "tool_axis_z", "turning_mode",
  "updated_at", "user_id", "xml") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
  </code></pre>
  
  <p>this is request and i think it looks well:</p>
  
  <pre><code>{"utf8"=&gt;"✓",
  "authenticity_token"=&gt;"2OLwcjq/92i4VyZvO5/0SuTosuiTzbNQtVgk+cxmPQY=",
  "conf"=&gt;{"machine_brand"=&gt;"mbrand3",
  "machine_model"=&gt;"mmodel3",
  "control_unit_brand"=&gt;"cbrand3",
  "control_unit_model"=&gt;"cmodel3",
  "tool_axis_x"=&gt;"10",
  "tool_axis_y"=&gt;"10",
  "tool_axis_z"=&gt;"10",
  "rotary_axis_number"=&gt;"3",
  "linear_axis_number"=&gt;"3",
  "turning_mode"=&gt;"t",
  "milling_mode"=&gt;"t",
  "description"=&gt;"desc",
  "xml"=&gt;#&lt;ActionDispatch::Http::UploadedFile:0x007f067099d180
  @original_filename="deneme.xml",
  @content_type="text/xml",
  @headers="Content-Disposition: form-data; name=\"conf[xml]\"; filename=\"deneme.xm
  \"\r\nContent-Type: text/xml\r\n",
  @tempfile=#&lt;File:/tmp/RackMultipart20130821-3666-1c0gsxu&gt;&gt;},
  "commit"=&gt;"Upload"}
  </code></pre>
  
  <p>this is my whole new.html.erb file:</p>
  
  <pre><code>&lt;% provide(:title, 'New Configuration')%&gt;
  &lt;h1&gt; Upload new configuration &lt;/h1&gt;
  
  &lt;div class="row"&gt;
    &lt;div class="span6 offset3"&gt;
  
  &lt;%= form_for (@conf, :html =&gt; {:multipart =&gt; true}) do |f| %&gt;
  
      &lt;%= f.label :machine_brand %&gt;
      &lt;%= f.text_field :machine_brand %&gt;
  
      &lt;%= f.label :machine_model %&gt;
      &lt;%= f.text_field :machine_model %&gt;
  
      &lt;%= f.label :control_unit_brand %&gt;
      &lt;%= f.text_field :control_unit_brand %&gt;
  
      &lt;%= f.label :control_unit_model %&gt;
      &lt;%= f.text_field :control_unit_model %&gt;
  
      &lt;%= f.label :tool_axis_x %&gt;
      &lt;%= f.text_field :tool_axis_x %&gt;
  
      &lt;%= f.label :tool_axis_y %&gt;
      &lt;%= f.text_field :tool_axis_y %&gt;
  
      &lt;%= f.label :tool_axis_z %&gt;
      &lt;%= f.text_field :tool_axis_z %&gt;
  
      &lt;%= f.label :rotary_axis_number %&gt;
      &lt;%= f.text_field :rotary_axis_number %&gt;
  
      &lt;%= f.label :linear_axis_number %&gt;
      &lt;%= f.text_field :linear_axis_number %&gt;
  
      &lt;%= f.label :turning_mode %&gt;
      &lt;%= f.text_field :turning_mode %&gt;
  
      &lt;%= f.label :milling_mode %&gt;
      &lt;%= f.text_field :milling_mode %&gt;
  
      &lt;%= f.label :description %&gt;
      &lt;%= f.text_field :description %&gt;
  
      &lt;%= f.label :xml %&gt;
      &lt;%= f.file_field :xml %&gt;
  
      &lt;%= f.submit "Upload", class: "btn btn-large btn-primary" %&gt;
  &lt;% end %&gt;
    &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>i think the problem is about create function and here it is:</p>
  
  <pre><code>def create
  
  @conf = Conf.new(params[:conf])
  
    if @conf.save
      flash[:success] = "New Configuration uploaded!"
      redirect_to @conf
    else
      flash[:error] = "There is a problem!"
      render 'new'
    end
  end
  </code></pre>
  
  <p>this is from routes.rb :</p>
  
  <pre><code>match '/conf_new', to:'confs#new'
  match '/conf_show', to:'confs#index'
  resources :confs
  </code></pre>
  
  <p>i have tried lots of ways and could not figure it out what is wrong. i tried to restart server, even restart computer :), lots of advices and codes from internet, but all failed.</p>
  
  <p><strong>edit</strong>: my conf model:</p>
  
  <pre><code>class Conf &lt; ActiveRecord::Base
  attr_accessible :linear_axis_number, :control_unit_brand, :control_unit_model, 
  :description, :developer_id, :machine_brand, :machine_model, :milling_mode, 
  :rotary_axis_number, :tool_axis_x, :tool_axis_y, :tool_axis_z, :turning_mode, :user_id, 
  :xml 
  
  belongs_to :developer, :class_name =&gt; 'User', :foreign_key =&gt; 'developer_id'
  belongs_to :receiver, :class_name =&gt; 'User', :foreign_key =&gt; 'user_id'
  end
  </code></pre>
  
  <p>ok i solved this problem. in create i changed redirect_to @conf  to  redirect_to conf_show_path and this error is no more</p>