title: How to pass params to new view in Ruby on Rails app?
body: <p>I'm trying to make simple app. I input my first name and last name to simple <code>&lt;%= form_for @data do |f| %&gt;</code> rails form and after submitting it, app should render simple text like this. <code>My first name is &lt;%= data.first_name %&gt; and my last name is &lt;%= data.last_name %&gt;</code>. I don't know why but my app is saying this error: </p>
  
  <blockquote>
    <p>undefined local variable or method `data' for</p>
  </blockquote>
  
  <p>It's probably saying it because no params are passed to view. </p>
  
  <p>Here is my code.</p>
  
  <p>routes.rb</p>
  
  <pre><code>resources :data, only: [:new, :create, :index]
  </code></pre>
  
  <p>data_controller.rb</p>
  
  <pre><code>class DataController &lt; ApplicationController
  
    def new
      @data = Data.new
    end
  
    def index
    end
  
    def create
      @data = Data.new(data_params) 
  
      if @data.valid?
        redirect_to @data
      else
        render :new
      end
    end
  
    private
      def data_params
        params.require(:data).permit(:first_name, :second_name)
      end
  end
  </code></pre>
  
  <p>/views/data/new.html.erb</p>
  
  <pre><code>&lt;%= form_for @data do |f| %&gt;
  
      &lt;%= f.label :first_name %&gt;
      &lt;%= f.text_field :first_name %&gt;
  
      &lt;%= f.label :second_name %&gt;
      &lt;%= f.text_field :second_name %&gt;
  
      &lt;%= f.submit 'Continue', class: 'button' %&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>/views/data/index.html.erb</p>
  
  <pre><code>&lt;h2&gt;Coolest app ever :D&lt;/h2&gt;
  &lt;p&gt;My first name is: &lt;%= data.first_name %&gt;.&lt;/p&gt;
  &lt;p&gt;And my second name is: &lt;%= data.second_name %&gt;.&lt;/p&gt;
  </code></pre>
  
  <p>/models/data.rb</p>
  
  <pre><code>class Data
    include ActiveModel::Model
    attr_accessor :first_name, :second_name
  
    validates :first_name, :second_name, presence: true 
  end
  </code></pre>
  
  <p>Please help to find out why params are not passing to next page. Thanks anyways :D</p>