title: ActionView::Template::Error: undefined method `StoreTitle' for nil:NilClass
body: <p>Updated version - I have taken the initial advice provided (thanks for that!) but I'm still having the same issue.  I have updated everything below.</p>
  
  <p>I have two models, products that belong to a store.</p>
  
  <p>I'm attempting to display a related object's column (Store.name) in a couple of views for products that belong to a store and can't seem to get the store to save correctly.  Please note: Still very new to this and learning.</p>
  
  <p><strong>Model for Product:</strong></p>
  
  <pre><code>    class Product &lt; ActiveRecord::Base
  
          belongs_to :store
          validates_presence_of :name, :url, :price
  
  
      end
  </code></pre>
  
  <p><strong>Model for Store:</strong></p>
  
  <pre><code>class Store &lt; ActiveRecord::Base
  
  has_many :products
  has_many :pins, through: :products
  accepts_nested_attributes_for :products
  
  end
  </code></pre>
  
  <p><strong>Controller for Product:</strong></p>
  
  <p>class ProductsController &lt; ApplicationController
        before_action :set_product, only: [:show, :edit, :update, :destroy]</p>
  
  <pre><code>  # GET /products
    # GET /products.json
    def index
      @products = Product.all
    end
  
    # GET /products/1
    # GET /products/1.json
    def show
    end
  
    # GET /products/new
    def new
      @product = Product.new
      @stores = Store.all
  
  
    end
  
    # GET /products/1/edit
    def edit
    end
  
    # POST /products
    # POST /products.json
    def create
      @product = Product.new(product_params)
  
      respond_to do |format|
        if @product.save
          format.html { redirect_to @product, notice: 'Product was successfully created.' }
          format.json { render action: 'show', status: :created, location: @product }
        else
          format.html { render action: 'new' }
          format.json { render json: @product.errors, status: :unprocessable_entity }
        end
      end
    end
  
    # PATCH/PUT /products/1
    # PATCH/PUT /products/1.json
    def update
      respond_to do |format|
        if @product.update(product_params)
          format.html { redirect_to @product, notice: 'Product was successfully updated.' }
          format.json { head :no_content }
        else
          format.html { render action: 'edit' }
          format.json { render json: @product.errors, status: :unprocessable_entity }
        end
      end
    end
  
    # DELETE /products/1
    # DELETE /products/1.json
    def destroy
      @product.destroy
      respond_to do |format|
        format.html { redirect_to products_url }
        format.json { head :no_content }
      end
    end
  
    private
      # Use callbacks to share common setup or constraints between actions.
      def set_product
        @product = Product.find(params[:id])
      end
  
      # Never trust parameters from the scary internet, only allow the white list through.
      def product_params
        params.require(:product).permit(:name, :description, :imageurl, :url, :price, :Store_id)
      end
  end
  </code></pre>
  
  <p><strong>Form for products</strong> </p>
  
  <pre><code>   &lt;%= form_for(@product) do |f| %&gt;
      &lt;% if @product.errors.any? %&gt;
        &lt;div id="error_explanation"&gt;
          &lt;h2&gt;&lt;%= pluralize(@product.errors.count, "error") %&gt; prohibited this product from being saved:&lt;/h2&gt;
  
          &lt;ul&gt;
          &lt;% @product.errors.full_messages.each do |msg| %&gt;
            &lt;li&gt;&lt;%= msg %&gt;&lt;/li&gt;
          &lt;% end %&gt;
          &lt;/ul&gt;
        &lt;/div&gt;
      &lt;% end %&gt;
  
      &lt;div class="form-group"&gt;
        &lt;%= f.label :name, "Name" %&gt;
        &lt;%= f.text_field :name, class: "form-control" %&gt;
      &lt;/div&gt;
      &lt;div class="form-group"&gt;
        &lt;%= f.label :description, "Description" %&gt;
        &lt;%= f.text_area :description, class: "form-control" %&gt;
      &lt;/div&gt;
      &lt;div class="form-group"&gt;
        &lt;%= f.label :imageurl, "Image" %&gt;
        &lt;%= f.text_field :imageurl, class: "form-control" %&gt;
      &lt;/div&gt;
      &lt;div class="form-group"&gt;
        &lt;%= f.label :url, "Web Address" %&gt;
        &lt;%= f.text_field :url, class: "form-control" %&gt;
      &lt;/div&gt;
      &lt;div class="form-group"&gt;
        &lt;%= f.label :price, "Price" %&gt;
        $&lt;%= f.text_field :price, class: "form-control" %&gt;
      &lt;/div&gt;
  
    &lt;div class="form-group"&gt;
    &lt;%= collection_select(:product, :Store_id, Store.all, :id, :name, {:prompt=&gt; "Select A Store"}, {:class =&gt; "form-control"} ) %&gt;
  
  
  
    &lt;/div&gt;
    &lt;div class="form-group"&gt;
         &lt;%= f.submit class: "btn btn-primary" %&gt;
      &lt;/div&gt;
    &lt;% end %&gt;
  
    &lt;%= params.inspect %&gt;
  </code></pre>
  
  <p><strong>View for products (show.html.erb):</strong></p>
  
  <pre><code>&lt;p id="notice"&gt;&lt;%= notice %&gt;&lt;/p&gt;
  
      &lt;p&gt;
        &lt;strong&gt;Name:&lt;/strong&gt;
        &lt;%= @product.name %&gt;
      &lt;/p&gt;
  
      &lt;p&gt;
        &lt;strong&gt;Description:&lt;/strong&gt;
        &lt;%= @product.description %&gt;
      &lt;/p&gt;
  
      &lt;p&gt;
        &lt;strong&gt;Store Id:&lt;/strong&gt;
        &lt;%= @product.Store_id %&gt;
      &lt;/p&gt;
  
      &lt;p&gt;
        &lt;strong&gt;Store Name:&lt;/strong&gt;
        &lt;%= @product.store.try(:name) %&gt;
      &lt;/p&gt;
  
  
      &lt;p&gt;
        &lt;strong&gt;Image:&lt;/strong&gt;
        &lt;%= @product.imageurl %&gt;
      &lt;/p&gt;
  
      &lt;p&gt;
        &lt;strong&gt;Url:&lt;/strong&gt;
        &lt;%= @product.url %&gt;
      &lt;/p&gt;
  
      &lt;p&gt;
        &lt;strong&gt;Price:&lt;/strong&gt;
        $&lt;%= @product.price %&gt;
      &lt;/p&gt;
  
      &lt;%= params.inspect %&gt;
  
      &lt;%= link_to 'Edit', edit_product_path(@product) %&gt; |
      &lt;%= link_to 'Back', products_path %&gt;
  </code></pre>
  
  <p>You'll notice that I have .try in place where I'm referencing product.store.name from product.store so that I stop getting the error listed in the subject of this post.  </p>
  
  <p>When I look up the product I'm viewing using the console I see that Store_id: 2</p>
  
  <p>When I look up the store with id of 2 I see that Store_id: 1 - so there is a value present there.</p>
  
  <p>I printed params on the show view and only get this: {"action"=>"show", "controller"=>"products", "id"=>"2"}.  </p>
  
  <p>Can anyone find what I'm missing in this whole set up to get product.store.name to display in my product views?  Let me know if I can provide more info! </p>