class Admin::ExperimentsController < OrbitAdminController before_filter :setup_vars def index @table_fields = [:image,:category,:subject,t('experiment.professor1')] @categories = @module_app.categories @tags = @module_app.tags @filter_fields = filter_fields(@categories, @tags) @subjects = Subject.order_by(sort) .with_categories(filters("category")) .with_tags(filters("tag")) .with_status(filters("status")) @subjects = search_data(@subjects,[:title]).page(params[:page]).per(10) render :partial => "index" if request.xhr? end def new @subject = Subject.new @tags = @module_app.tags @categories = @module_app.categories # respond_to do |format| # format.html # new.html.erb # end end def create # render :text =>"#{params[:subject]}" @subject = Subject.new(create_params) @subject.save redirect_to params['referer_url'] end def edit @subject = Subject.find(params[:id]) if can_edit_or_delete?(@subject) @tags = @module_app.tags @categories = @module_app.categories else render_401 end end def update @subject = Subject.find(params[:id]) bps = create_params bps[:email_member_ids] = bps[:email_member_ids].blank? ? [] : bps[:email_member_ids] bps[:co_professor_ids] = bps[:co_professor_ids].blank? ? [] : bps[:co_professor_ids] # @subject[:email_member_ids] = @subject[:email_member_ids].blank? ? [] : @subject[:email_member_ids] @subject.update_attributes(bps) @subject.save redirect_to params['referer_url'] end def destroy @subject = Subject.find(params[:id]) @subject.destroy redirect_to admin_experiments_path end private def setup_vars @module_app = ModuleApp.where(:key => "experiment").first end def create_params params.require(:subject).permit! end end