0
我有一個表單,用戶從下拉列表中選擇一個類別。這是在我看來代碼:collection_select行爲不端
<%= collection_select(:project_categories, :id, Project_Category.all, :id, :category_name) %>
所有形式的其他領域(是的,collection_select是一個表單內)中保存並從數據庫中讀取預期。但不是collection_select ...
這裏是模型:
class Project < ActiveRecord::Base
attr_accessible :category,
...
belongs_to :user
has_one :category
...
end
控制器:
def create
@user = current_user
@project = current_user.build_project(params[:project])
@project.save
render 'edit'
end
...
def update
@project = Project.find(params[:id])
@user = current_user
@project.current_step = session[:step]
end
...
private
def correct_user
@project = current_user.project
redirect_to show_user_path if @project.nil?
end
def has_project
@project = current_user.projects.find_by_id(params[:id])
end
end
Project_Category?那是什麼? – 2013-02-13 01:30:22