add multiple id in dropdown in admin side form at browser

Note :  we have to add the multiple email ids in sender receiver cc and bcc in drop down in the admin ::::::::: 

1..............................................

in this form -- 

  form do |f|

    f.inputs do

      f.input :name

      f.input :sender_email, as: :select, collection: AccountBlock::Account.all.map{|e| ["#{e.name} - <#{e.email}>",e.email]},include_blank: false, :input_html => {:width => 'auto', multiple: true}

      f.input :cc_email  

      f.input :bcc_email 

      f.input :subject 

      f.input :description

    end

    f.actions

  end

end

..................................

use this --- for 

      f.input :sender_email, as: :select, collection: AccountBlock::Account.all.map{|e| ["#{e.name} - <#{e.email}>",e.email]},include_blank: false, :input_html => {:width => 'auto', multiple: true}

 2 ..............................................

note -  simple 

      f.input :email

agar likhenge toh output mein email ki value blank ayegi - value ja rahi hai lekin ayegi nai - kyunki humne email ka column string liya hai schema mein lekin default mein array liya hai - so value multiple save hongi aur multiple values ko save karane ke liye humko 

      f.input :sender_email, as: :select, collection: AccountBlock::Account.all.map{|e| ["#{e.name} - <#{e.email}>",e.email]},include_blank: false, :input_html => {:width => 'auto', multiple: true}

sath mein collection lagana padhega aur sath mein value ko map karna padhega 



use this for cc_email and bcc_email also :: 

f.input :sender_email, as: :select, collection: AccountBlock::Account.all.map{|e| ["#{e.name} - <#{e.email}>",e.email]},include_blank: false, :input_html => {:width => 'auto', multiple: true}

       f.input :cc_email, as: :select, collection: AccountBlock::Account.all.map{|e| ["#{e.name} - <#{e.email}>",e.email]},include_blank: false, :input_html => {:width => 'auto', multiple: true}

        f.input :bcc_email, as: :select, collection: AccountBlock::Account.all.map{|e| ["#{e.name} - <#{e.email}>",e.email]},include_blank: false, :input_html => {:width => 'auto', multiple: true}

 3 ..............................................

add these two methods - in email_template  -- 

+               validates_presence_of :name, { message: "Name can't be blank" }

+               validates_presence_of :subject, { message: "Subject can't be blank" }

.......................................................................................................................................................

4 ..............................................

add these two methods - in invoice_template  -- 

validates_presence_of :name, { message: "Invoice name can't be blank" }

+               validates_presence_of :subject, { message: "Invoice subject can't be blank" }

5 ..............................................

add this method in account.rb  -- 

    def name

      self.first_name.present? ? self.first_name : ""

    end

6 ..............................................

add these controllers in admin/invoice_template.rb  -- 

i use byebug in simple method with super 

def create 

byebug

super

end

.....................

and then i check this code with the byebug and then i take it inside controller 

after testing at byebug 

......................................................................................................................

   controller do

    def create

      params[:bx_block_invoice_template_invoice_template][:sender_email]=  params[:bx_block_invoice_template_invoice_template][:sender_email].reject { |c| c.empty? }

      params[:bx_block_invoice_template_invoice_template][:cc_email]=  params[:bx_block_invoice_template_invoice_template][:cc_email].reject { |c| c.empty? }

      params[:bx_block_invoice_template_invoice_template][:bcc_email]=  params[:bx_block_invoice_template_invoice_template][:bcc_email].reject { |c| c.empty? }

      super

    end

......................................................................................................................

    def update

      params[:bx_block_invoice_template_invoice_template][:sender_email]=  params[:bx_block_invoice_template_invoice_template][:sender_email].reject { |c| c.empty? }

      params[:bx_block_invoice_template_invoice_template][:cc_email]=  params[:bx_block_invoice_template_invoice_template][:cc_email].reject { |c| c.empty? }

      params[:bx_block_invoice_template_invoice_template][:bcc_email]=  params[:bx_block_invoice_template_invoice_template][:bcc_email].reject { |c| c.empty? }

      super

    end

   end

......................................................................................................................

7.
controller do
def create 
super 
end
def update 
super 
end
end










Comments

Popular posts from this blog

Rails 7 Features :: Comparison with Rails 6 and Rails 5