title: How do I add autofocus to a form field if it is the edit form?
body: <p>I am new to ruby on rails and working through the Rails Tutorial book and also Rails Programming from pragmatic studio. However for my project I need to find solutions now so sad I can't spend more time on the researching.</p>
  
  <p>My question is, once I am able to add, show and edit forms I am being instructed to create partials, ie _forms.html.erb and then rendering those forms on the edit, show and new pages.</p>
  
  <p>On my _forms.html.erb partial, how can I implement some flow using if statements based on the page that the form is being rendered for.</p>
  
  <p>For example, when _form.html.erb is being rendered for the show page I want certain form_for labels/fields to be set to readonly: true. At the bottom of the form I want submit, edit, change buttons based on the page aswell.</p>
  
  <p>So far I am trying to use the parems[:action] == "new" or "edit" etc to implement the control flow as follows:</p>
  
  <p>Old code under the edit.html.erb file:</p>
  
  <pre><code>      &lt;%= f.label :patform_type %&gt;
        &lt;%= f.text_field :patform_type,autofocus: true %&gt;
  </code></pre>
  
  <p>New code under the _form.html.erb file:</p>
  
  <pre><code>      &lt;%= f.label :patform_type %&gt;
        &lt;%= f.text_field :patform_type %&gt;
          &lt;% if params[:action] == "new" %&gt;
            &lt;%= ,autofocus: true %&gt;
          &lt;% end %&gt;
  </code></pre>
  
  <p>My original code has been influenced by these posts:
  <a href="https://stackoverflow.com/questions/5620128/rails-not-editable-text-field">Rails not editable text field</a>
  <a href="https://stackoverflow.com/questions/13219315/how-to-disable-all-form-for-input-fields-in-ruby-on-rails-app">How to disable all form_for input fields in Ruby on Rails app?</a></p>
  
  <p>Once I get this right then I am hoping I can use it to wrap it around other elements like the submit, edit buttons etc or other fields.</p>
  
  <p>Also if someone knows a better way can you please let me know as I don't know what I don't know.</p>
  
  <p>Thanks for any assistance/ideas you can provide.</p>