2014-09-25 23:32:08 +08:00
|
|
|
class Admin::UserFieldsController < Admin::AdminController
|
|
|
|
|
|
|
|
def create
|
2014-10-03 03:56:28 +08:00
|
|
|
field = UserField.new(params.require(:user_field).permit(:name, :field_type, :editable, :description))
|
|
|
|
json_result(field, serializer: UserFieldSerializer) do
|
|
|
|
field.save
|
|
|
|
end
|
2014-09-25 23:32:08 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def index
|
|
|
|
render_serialized(UserField.all, UserFieldSerializer, root: 'user_fields')
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
|
|
|
field_params = params.require(:user_field)
|
|
|
|
|
|
|
|
field = UserField.where(id: params.require(:id)).first
|
|
|
|
field.name = field_params[:name]
|
|
|
|
field.field_type = field_params[:field_type]
|
2014-10-03 03:56:28 +08:00
|
|
|
field.description = field_params[:description]
|
2014-09-27 02:48:34 +08:00
|
|
|
field.editable = field_params[:editable] == "true"
|
2014-09-25 23:32:08 +08:00
|
|
|
|
2014-10-03 03:56:28 +08:00
|
|
|
json_result(field, serializer: UserFieldSerializer) do
|
|
|
|
field.save
|
|
|
|
end
|
2014-09-25 23:32:08 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
field = UserField.where(id: params.require(:id)).first
|
|
|
|
field.destroy if field.present?
|
|
|
|
render nothing: true
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|