app/controllers/phcmemberspro/members/mains_controller.rb in phcmemberspro-1.6.1 vs app/controllers/phcmemberspro/members/mains_controller.rb in phcmemberspro-1.6.3

- old
+ new

@@ -1,67 +1,87 @@ require_dependency "phcmemberspro/application_controller" module Phcmemberspro - class Members::MainsController < ApplicationController - + class Members::ContactsController < ApplicationController + # Security & Action Filters - # before_filter :authenticate_user! + before_filter :authenticate_user! layout 'layouts/phcmemberspro/members/members_all.html.erb' - before_action :set_members_main, only: [:show, :edit, :update, :destroy] + before_action :set_members_contact, only: [:show, :edit, :update, :destroy] - # Member Profile List + # Add Member Contact Information + before_action :phc_member_mains_info + + def phc_member_mains_info + @main = Members::Main.find(params[:main_id]) + end + + # Member Contact Index def index - @members_mains = Members::Main.current_user + main = Members::Main.find(params[:main_id]) + @members_contacts = main.contacts.scoped_to(current_account).order('mccontactname ASC') end - # Detailed Member Profile + # Detailed Member Contact Information def show + main = Members::Main.find(params[:main_id]) + @members_contact = main.contacts.scoped_to(current_account).find(params[:id]) end - # New Member Profile + # New Contact def new - @members_main = Members::Main.current_user.new + main = Members::Main.find(params[:main_id]) + @members_contact = main.contacts.scoped_to(current_account).build + respond_to do |format| + format.html # new.html.erb + format.xml { render :xml => @members_contact } + end end - # Edit Member Profile + # Edit Contact def edit + main = Members::Main.find(params[:main_id]) + @members_contact = main.contacts.scoped_to(current_account).find(params[:id]) end - # Create Member Profile Action + # Create Action def create - @members_main = Members::Main.current_user.new(members_main_params) - if @members_main.save - redirect_to members_mains_path, notice: 'Member profile was successfully created.' + @main = Members::Main.find(params[:main_id]) + @members_contact = @main.contacts.scoped_to(current_account).create(members_contact_params) + if @members_contact.save + redirect_to members_main_contacts_path, notice: 'Member contact information was successfully created.' else render :new end end - # Update Member Profile Action + # Update Action def update - if @members_main.current_user.update(members_main_params) - redirect_to members_mains_path, notice: 'Member profile was successfully updated.' + if @members_contact.scoped_to(current_account).update(members_contact_params) + redirect_to members_main_contacts_path, notice: 'Member contact information was successfully updated.' else render :edit end end - # Delete Member Profile Action + # Delete Action def destroy - @members_main.current_user.destroy - redirect_to members_mains_path, notice: 'Member profile was successfully destroyed.' + @main = Members::Main.find(params[:main_id]) + @members_contact = @main.contacts.scoped_to(current_account).find(params[:id]) + @members_contact.destroy + redirect_to members_main_contacts_path, notice: 'Member contact information was successfully destroyed.' end private # Common Callbacks - def set_members_main - @members_main = Members::Main.current_user.find(params[:id]) + def set_members_contact + @members_contact = Members::Contact.find(params[:id]) end # White List - def members_main_params - params.require(:members_main).permit(:mfirstname, :mlastname, :mtitle, :memail, :mphone, :mnotes, :user_id) + def members_contact_params + params.require(:members_contact).permit(:mccontactname, :mccompanyname, :mcaddressl1, :mcaddressl2, :mccity, :mcprovince, :mccountry, :mcpostalcode, :mcphone, :mcwebsite, :mcemail, :main_id, :account_id) end end -end +end \ No newline at end of file