Join the Stack Overflow Community
Stack Overflow is a community of 6.3 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

I have association for my School model:

class School < ActiveRecord::Base

  belongs_to :city
  has_many :sclasses
  has_many :users, through: :sclasses

  validates :name, presence: true
  validates :icon_url, length: { maximum: 100 }

end

And this is the part of schools#show view which makes me a problem:

<%= search_form_for @search, url: school_path(@city, @school) do |f| %>
    <div class="row input-field">
        <div class="text-center">
            <%= f.text_field :full_name_cont, placeholder: "Pretraga učenika" %>
        </div>
    </div>
    <div class="row input-field">
        <div class="text-center">
            <%= f.select :generation_eq, options_from_collection_for_select(@school.users.order("generation DESC").select(:generation).uniq, "generation", "generation", @search.generation_eq), {}, { :class => "selectpicker" } %>
        </div>
    </div>
    <div class="row input-field">
        <div class="text-center">
            <%= f.submit "Traži", class: "btn btn-default" %>
        </div>
    </div>
<% end %>

In this part I have the form for searching users which was there when structure of models looked like this:

City has_many School has_many Users

Now it looks like this:

City has_many School has_many Sclasses has_many Users

And I get this error:

PG::UndefinedColumn: ERROR:  column users.sclass_id does not exist
LINE 1: ...generation" FROM "users" INNER JOIN "sclasses" ON "users"."s...
                                                             ^
HINT:  Perhaps you meant to reference the column "users.sclass".
: SELECT DISTINCT "users"."generation" FROM "users" INNER JOIN "sclasses" ON "users"."sclass_id" = "sclasses"."id" WHERE "sclasses"."school_id" = $1  ORDER BY generation DESC

How should I change parameter in the f.select to make this work properly?

share|improve this question

Problem is solved; I checked db/schema.rb and there was an integer column called sclass instead of sclass_id (I probably forgot to make it with references type in migration).

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.