title: Ruby rails - form is invalid
body: <p>To create a new user I use a search view to find user info in ldap and populate the data in the new user creation form. Then submitting that form will create a new user locally in mysql. So the new user create form is already populated and I can the values. But after submitting that form the page comes back with message saying the fields were blank. Not sure why is that. In http debug I see those values were posted to /users/new</p>
  
  <pre><code>Form is invalid
  
  User can't be blank
  Firstname can't be blank
  Lastname can't be blank
  Email can't be blank
  Role can't be blank
  </code></pre>
  
  <p>Controller - </p>
  
  <pre><code>class UsersController &lt; ApplicationController
  
  
    def new
          @user = User.new
          @result = User.FindActiveDirectory(params[:user_id])
      if @result.empty?
          render action: 'find', message: "Could not find a user with the id #{params[:user_id]}"
  else
      return @result
  
      end
  
    end
  
  def find
  end
  
  
  def display_result
  
      @result = User.FindActiveDirectory(params[:user_id])
      if @result.empty?
          render action: 'find', message: "Could not find a user with the id #{params[:user_id]}"
      end
  return @result
  end
  
  
    def create
  
          @user = User.new(params[:user_id])
          if @user.save
                  redirect_to users_added_url, :notice =&gt; "Signed up!"
          else
                  render "new"
          end
    end
  
  end
  </code></pre>
  
  <p>User view find (find.html.erb) - </p>
  
  <pre><code>&lt;h1&gt;find User &lt;/h1&gt;
  &lt;p&gt;&lt;%= notice %&gt;&lt;/p&gt;
  
  &lt;%= form_tag users_new_path do %&gt;
    &lt;p&gt;
      &lt;%= label_tag :Username %&gt;&lt;br /&gt;
      &lt;%= text_field_tag :user_id %&gt;
    &lt;/p&gt;
    &lt;p class="button"&gt;&lt;%= submit_tag " Search " %&gt;&lt;/p&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>Users view create new (new.html.erb)- </p>
  
  <pre><code>&lt;h1&gt;Add user to access this system&lt;/h1&gt;
  
  &lt;% if @result %&gt;
  &lt;% @result.each do |key, values| %&gt;
  &lt;% if "#{key}" == "samaccountname" %&gt;
  &lt;% $username = values.to_s %&gt;
  &lt;% end %&gt;
  &lt;% if "#{key}" == "sn" %&gt;
  &lt;% $lastname = values.to_s %&gt;
  &lt;% end %&gt;
  &lt;% if "#{key}" == "givenname" %&gt;
  &lt;% $firstname = values.to_s %&gt;
  &lt;% end %&gt;
  &lt;% if "#{key}" == "mail" %&gt;
  &lt;% $email = values.to_s %&gt;
  &lt;% end %&gt;
  &lt;% end %&gt;
  &lt;% end %&gt;
  
  
  &lt;%= form_for @user do |f| %&gt;
    &lt;% if @user.errors.any? %&gt;
      &lt;div class="error_messages"&gt;
        &lt;h2&gt;Form is invalid&lt;/h2&gt;
        &lt;ul&gt;
          &lt;% for message in @user.errors.full_messages %&gt;
            &lt;li&gt;&lt;%= message %&gt;&lt;/li&gt;
          &lt;% end %&gt;
        &lt;/ul&gt;
      &lt;/div&gt;
    &lt;% end %&gt;
   &lt;p&gt;
      &lt;%= f.label :NT_Username %&gt;&lt;br /&gt;
      &lt;%= f.text_field :user_id, :value =&gt; $username  %&gt;
    &lt;/p&gt;
   &lt;p&gt;
      &lt;%= f.label :Firstname %&gt;&lt;br /&gt;
      &lt;%= f.text_field :firstname, :value =&gt; $firstname  %&gt;
    &lt;/p&gt;
   &lt;p&gt;
      &lt;%= f.label :Lastname %&gt;&lt;br /&gt;
      &lt;%= f.text_field :lastname, :value =&gt; $lastname %&gt;
    &lt;/p&gt;
    &lt;p&gt;
      &lt;%= f.label :Email %&gt;&lt;br /&gt;
      &lt;%= f.text_field :email, :value =&gt; $email %&gt;
    &lt;/p&gt;
    &lt;p&gt;
      &lt;%= f.label :Role %&gt;&lt;br /&gt;
      &lt;%= f.collection_select :role, User::ROLES, :to_s, :to_s, :include_blank =&gt; false %&gt;
    &lt;/p&gt;
    &lt;p class="button"&gt;&lt;%= f.submit %&gt;&lt;/p&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>Request - </p>
  
  <pre><code>Started POST "/users" for 10.15.21.28 at 2012-04-07 00:00:17 -0400
  Processing by UsersController#create as HTML
    Parameters: {"utf8"=&gt;"â", "authenticity_token"=&gt;"RDxvWXxVwoJArNN1s4Q8M8cDr5rzjP4wNF4gOnteGGY=", "user"=&gt;{"user_id"=&gt;"jkills000", "firstname"=&gt;"James", "lastname"=&gt;"Kills", "email"=&gt;"jkills000@mysite.com", "role"=&gt;"User"}, "commit"=&gt;"Create User"}
  </code></pre>