mercredi 8 juin 2016

Need to genrate bills for all users in rails, what should be create method?

Hi,

I need to generate bills for all users (residents) in my app, the bill_controller's create method looks like :

    def create
    resident = Resident.find_by(hostel:current_admin_user.hostel) # current_admin_user  action is provided by Activeadmin to access current activeadmin user details 
      @bill=resident.bills.create(bill_params)
      if @bill.save
        flash[:info] = "Bills Generated  successfully"
        redirect_to new_bill_path
      else
        flash[:danger] = "Bills Not generated, Please try again!"
        redirect_to new_bill_path

      end
  end

The active admin users can generate bills, and bills will be generated only for residents that have same hostel with admin user ! And bills should be generated for all residents with specific hostel. check out my code, right now it is generating only for current user(resident logged in) . thanks !

Aucun commentaire:

Enregistrer un commentaire