title: Rails Generator Pass an Array of Arguments
body: <p>I've looked at the rails casts on how to create your own generator and have read a number of stack overflow questions. Basically what I am trying to do is to build a generator like the built-in rails migration generator where it takes arguments like <code>attribute:type</code> and then inserts them as necessary. Here is the code I have now for my generator.</p>
  
  <pre><code>class FormGenerator &lt; Rails::Generators::NamedBase
    source_root File.expand_path('../templates', __FILE__)
    argument :model_name, :type =&gt; :string
    argument :attributes, type: :array, default: [], banner: "attribute:input_type attribute:input_type"
    argument :input_types, type: :array, default: [], banner: "attribute:input_type attribute:input_type"
  
  
  
    def create_form_file
      create_file "app/views/#{model_name.pluralize}/_form.html.erb", "
  
  
  &lt;%= simple_form_for @#{model_name.pluralize} do | f | %&gt;
  &lt;%= f.#{input_type}  :#{attribute}, label: '#{attribute}' %&gt;
  &lt;% end %&gt;
  "
    end
  end
  </code></pre>
  
  <p>Essentially what I want it to do is generate a view file with as many lines as there are arguments. So passing <code>rails g form products name:input amount:input other_attribute:check_box</code> would generate a <code>_form.html.erb</code> file with the following:</p>
  
  <pre><code>&lt;%= simple_form_for @products do | f | %&gt;
      &lt;%= f.input  :name, label: 'name' %&gt;
      &lt;%= f.input  :amount, label: 'amount' %&gt;
      &lt;%= f.check_box  :other_attribute, label: 'other_attribute' %&gt;
      &lt;% end %&gt;
  </code></pre>
  
  <p>How would I write the generator to take multiple arguments and generate multiple lines based on those arguments?</p>