会社モデルとユーザーモデルがあります。ユーザーは会社に属します会社には多くのユーザーがいます。会社が設立され、人々は個別にサインアップすることができ、それが協会を作成します。私は選択ボックスを作成しようとしているので、ユーザーがサインアップするときに、会社モデルのpluckメソッドを使用して入力された選択ボックスから会社を選択します。
ユーザーがサインアップすると、選択ボックスが空であると表示されます...空ではないように見えますが。私は何が間違っているのですか?
会社モデル
class Company < ActiveRecord::Base
attr_accessible :company_admin, :company_name, :employee_number, :street_address, :city, :state_abbreviation, :zip_code
has_many :users
validates :company_admin, presence: true
validates :company_name, presence: true, uniqueness: { case_sensitive: false }
validates :employee_number, presence: true
validates :street_address, presence: true
validates :city, presence: true
validates :state_abbreviation, presence: true
validates :zip_code, presence: true
end
ユーザーモデル
class User < ActiveRecord::Base
attr_accessible :company, :name, :email, :password, :password_confirmation, :image, :team_id
belongs_to :company
end
企業コントローラー
class CompaniesController < ApplicationController
before_filter :signed_in_user, only: [:show, :edit, :update, :destroy]
def show
@company = Company.find(params[:id])
end
def new
@company = Company.new
end
def create
@company = Company.new(params[:company])
if @company.save
redirect_to signup_path
else
render 'new'
end
end
def update
if @company.update_attributes(params[:company])
flash[:success] = "Company Information Updated"
sign_in @company
redirect_to @company
else
render 'edit'
end
end
end
新しいユーザービュー
<%= form_for(@user) do |f| %>
<%= f.label :company, :class => 'col-left' %>
<%= collection_select(:company_id, :company_id, Company.all, :id, :company_name, {:include_blank => true}) %>
<%= f.label :email, :class => 'col-left' %>
<%= f.text_field :email, :class => 'col-right' %>
<%= f.label :name, :class => 'col-left' %>
<%= f.text_field :name %>
<%= f.label :password, :class => 'col-left' %>
<%= f.password_field :password %>
<%= f.label :password_confirmation, "Confirm Password", :class => 'col-left' %>
<%= f.password_field :password_confirmation %>
<%= image_submit_tag "/assets/create-account.png" %>
<% end %>