Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6106709
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:06:32+00:00 2026-05-23T14:06:32+00:00

I am new to RoR and have run into a problem that has been

  • 0

I am new to RoR and have run into a problem that has been driving me crazy, which I can’t figure out!

Basically, I have created a product form and added a ‘Supplier’ select field, which finds all my suppliers but now when I try to update a current product or create a new one, I get the following error:

ActiveRecord::AssociationTypeMismatch in ProductsController#create
Supplier(#2178099880) expected, got String(#2148287480)

I understand what the error is telling me, but I don’t understand why. I have also created an association for product category the same way, which works fine!

Also, if I add a validation to validate the presence of supplier, I get a ‘supplier can’t be blank’ error, even if a supplier is selected.

Would really appreciate some help on this!

In my _form.html I have:

<%= f.label :supplier %>
<%= f.select(:supplier, Supplier.find(:all).collect {|c| [ c.name, c.id ]}, :include_blank => true) %>

Products Controller:

class ProductsController < ApplicationController
  # GET /products
  # GET /products.xml
  def index
    @products = Product.all

    respond_to do |format|
      format.html # index.html.erb
      format.xml  { render :xml => @products }
    end
  end

  # GET /products/1
  # GET /products/1.xml
  def show
    @product = Product.find(params[:id])

    respond_to do |format|
      format.html # show.html.erb
      format.xml  { render :xml => @product }
    end
  end

  # GET /products/new
  # GET /products/new.xml
  def new
    @product = Product.new

    respond_to do |format|
      format.html # new.html.erb
      format.xml  { render :xml => @product }
    end
  end

  # GET /products/1/edit
  def edit
    @product = Product.find(params[:id])
  end

  # POST /products
  # POST /products.xml
  def create
    @product = Product.new(params[:product])

    respond_to do |format|
      if @product.save
        format.html { redirect_to(@product, :notice => 'Product was successfully created.') }
        format.xml  { render :xml => @product, :status => :created, :location => @product }
      else
        format.html { render :action => "new" }
        format.xml  { render :xml => @product.errors, :status => :unprocessable_entity }
      end
    end
  end

  # PUT /products/1
  # PUT /products/1.xml
  def update
    @product = Product.find(params[:id])

    respond_to do |format|
      if @product.update_attributes(params[:product])
        format.html { redirect_to(@product, :notice => 'Product was successfully updated.') }
        format.xml  { head :ok }
      else
        format.html { render :action => "edit" }
        format.xml  { render :xml => @product.errors, :status => :unprocessable_entity }
      end
    end
  end

  # DELETE /products/1
  # DELETE /products/1.xml
  def destroy
    @product = Product.find(params[:id])
    @product.destroy

    respond_to do |format|
      format.html { redirect_to(products_url) }
      format.xml  { head :ok }
    end
  end
end

Product Model:

class Product < ActiveRecord::Base

  belongs_to :supplier
  belongs_to :categories
  default_scope :order => 'product_number'

  validates_presence_of :product_name, :product_number, :category, :opening_order, :initial_cover,
  :country_of_origin, :supplier

  validates_uniqueness_of :product_number

  # Paperclip

  has_attached_file :image, :styles => { :medium => "300x300>", :thumb => "100x100>" }
end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T14:06:32+00:00Added an answer on May 23, 2026 at 2:06 pm

    Instead of creating form fields for supplier try creating them for supplier_id:

    <%= f.label :supplier_id %>
    <%= f.select(:supplier_id, Supplier.find(:all).collect {|c| [ c.name, c.id ]}, :include_blank => true) %>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Am new to RoR paperclip gem and i have been trying out some examples
I'll preface this with the fact that I'm new to RoR. I have a
I'm fairly new to RoR I have a controller and within that controller I
New to all coding worlds and new to RoR. I have been doing a
I am new to RoR, any help would be greatly appreciated :) I have
I have a problem running RoR project. I am getting this error while running
I have a RoR app running rails 2.3.8 which makes use of the Rails
I am new to RoR and still playing with associations. I need to have
I have RoR 3.0 web application which is acting as an OAuth API provider.
This issue has been previously reported, but I still have not been able to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.