class Admin::MemberInfosController < OrbitMemberController before_action :set_attribute before_action :set_member_info, only: [:edit, :update, :show, :destroy] helper Admin::AttributeValuesViewHelper def index @attributes = MemberInfo.order('created_at DESC') @roles = Role.excludes('disabled' => true) end def new @attribute = MemberInfo.new render layout: false end def show end def edit end def create @attribute = MemberInfo.new(member_info_params) @attribute.save redirect_to action: :index end def update if info_params[:attribute_fields].present? info_params[:attribute_fields].each do |a| field_status = a.last[:id].present? @attribute_field = MemberProfileField.add_attribute_field(@attribute, a.last, a.last[:id], field_status) end @attribute.member_profile_fields.each{|t| t.destroy if t["to_delete"] == true} respond_to do |format| format.js { render 'admin/member_infos/add_attribute_field' } end else @attribute.update_attributes(member_info_params) @attribute.member_profile_fields.each{|t| t.destroy if t["to_delete"] == true} respond_to do |format| format.html { redirect_to(admin_member_infos_path) } format.js { render 'admin/member_infos/toggle_enable' } end end end def destroy @attribute.destroy respond_to do |format| format.html { redirect_to admin_member_infos_path } format.js { render 'admin/member_infos/destroy' } end end private # Use callbacks to share common setup or constraints between actions. def set_member_info @attribute = MemberInfo.find(params[:id]) end def info_params params.require(:info).permit! end def member_info_params params.require(:member_info).permit! end protected def set_attribute @attribute_type = 'info' @class = 'infos' end end