Luca Rossi

Joined

320 Experience
0 Lessons Completed
0 Questions Solved

Activity

Posted in DB Structure for custom forms

Hey Jacob no need to be sorry, as a matter of fact I was looking for other's opinion on this one and your information was very relevant so thanks again.

I have been using this article as example http://mobyinc.com/labs/building-a-dynamic-form-system. It does more and less what I describe above. The only difference is that I might still use formbuilder.js rather than rebuild the form creation UI myself for now and store each field to the form_fields table in the model running through the formbuilder json string. 

Posted in DB Structure for custom forms

Hey Jacob thanks for your reply !

If you have your associations set up, then just create an update function that goes through each form that used that template and update accordingly for the changes made to the template. There may be a more efficient way to handle this if you're dealing with thousands of records that need to be updated at once.

I think perhaps I should keep form template structure and values separate and only make references to both in records. That way when the template changes all record entries automatically change (This needs some sort of archive functionality so that data deleted when fields are deleted is not completely lost).


Ciao,
Luca

Posted in DB Structure for custom forms

Bump.

Posted in DB Structure for custom forms

Hi all,

I am building an app that has the ability to create/edit forms with custom fields as a feature. Form templates can be assigned to personal record to be completed by users (google forms? :) )

I am using PG with schemas and formbuilder.js to build the form. Right now I am saving the template as a JSON string, which is copied to the record data column (as a JSON string) is created and modified when the form is saved (in the model) by adding the values to the record

  • I would like to move from this method as it has some limitations, one being that by modifying the form template (i.e. adding/removing fields) every existing record should be also modified.
  • I would like to attach multiple forms to a single record
  • I am also not sure JSON string manipulation is the right/most efficient way

How would you structure the db/solution?

Thanks!

Posted in Organising per view javascripts

Hi all,

I am refactoring my app since it is the first one and I have been doing the wrong things :)

This topic is about javascript assets. I have moved all the vendor libraries to the vendor folder and swapped min files with normal since rails does compress all.

I was also including page specific .js files in view depending on the libraries I needed and I have moved the bulk back to application.js as I noticed this was not the best practice.

Now I am dealing with view specific javascript. I am using this approach from Brandon Hilkert: controller and action name in body tag and return unless the relevant controller/action are shown.

Almost every controller index uses bootstrap table to list model items. These tables are initialised with javascript and some of the code such as action buttons and columns differ. Also the new/edit action for the same controller has specific javascript handling different features.

Following the above approach I could either create a separate file for each controller action (i.e. one for index and one for edit for each controller).

Is this a good approach or would you recommend something else?

Thanks!




Hi guys wanted to get some feedback on the way I have been using In my first app I am using both array (text) and jsonb columns. I am using these instead of additional DB tables since the structure in each record will be different and I do not intend to search into them.

The array text column is used to:

  • store operating hours for each store
  • store consultation appointment time slots (min length is 15 = 1 slot, so a 1 hour consultation = 4 slots). I am storing an array with the slot numbers as I need all slots when I calculate the available timeslots for new consultations (all slots - busy slots = available slots)

The JSONB columns are used to manage form templates and values:
One columns is used to store form templates created using formbuilder.js in the tforms table. The other is used to store both form and data in the actual consultation table: when a consultation is created, the template from the forms table is saved to the consultation form column. From this point on every time the consultation is accessed the form and inputs are accessed/saved in the local column. This way the form template can be modified for future consultations and the old data is preserved (i need to add a function that allows users to add newly added fields to existing consultations if required).

All works fine for now on the prototype. However, I wonder if anyone would have done things in a different way..

Thanks in advance for your time!

Luca

Thank for sharing your solution Jacob (and Drilon for asking this question before me!)

I am going to use fullcalendar to display available appointments (clickable). Staff users will need to enter the session length before they can open the calendar with the available options.

The calendar will use ajax to access the available slots from the user controller. The controller will remove all existing bookings for the specific consultant in the appointments table and return all remaining available ones. The use of slots (15minutesx96) will help with dealing with different appointment lenghts.

Luca

Hi Jacob, what did you use for the appointment selection in the view? A calendar?

Ok, I solved the login redirection issue by using active_for_authentication? in user.rb to return true and allow the login only if the user is the owner in the case the account is expired.

  # Check if account is active or throw error
  def active_for_authentication?
    super && self.is_active
  end

  def inactive_message
    "Sorry, this account has been deactivated. Contact your employer for more information."
  end

  def is_active
    if self.business.expires > Date.today || self.role == 'owner'
      return true
    end
  end

I then redirect to the subscritpion page using before_action in the application controller where I check again if the subscription is expired.


        before_action :verify_subscription, :if => :user_signed_in?

    def verify_subscription
      if current_user.business.expires < Date.today
        redirect_to :subscription unless['SubscriptionController', 'SessionsController'].include?(self.class.to_s)
      end
    end

Hi all!

I developed an app that uses Apartment for multitenancy, Devise for authentication and Pundit for auth. Each tenant is represented by a business (business model), where the id is also the tenant id. Businesses can have multiple users depending on the purchased plan yet to be implemented.

Each business will have an "owner" user, who will also be the first user created along with tenant (along with a few other tables in the tenant's schema. Business and User models are excluded from tenancy in Apartment.

I was hoping I could get some help/direction with the following:

  • Being the business table also the tenants table, would you hold the account information straight into this table or create an additional account table?

  • Since each business (account) can have multiple users, I am trying to figure out a solution to allow only the owner to manage the subscription and also to handle login attempts to expired account (i.e. fail any attempt from non owner users or redirect to subscription for renewal if the owner attempts to login)

Right now I am using Devise's active_for_authentication? in user.rb to check if the account is expired. If the logged user is also the owner, i then throw an exception that is handled in the application controller with a redirect to the subscription page. The problem is that the redirect then re-triggers the active_for_authentication? check causing a loop. Been trying different options such as checking if the current controller is subscriptions and stopping the active_for_authentication? but at this point I am not sure anymore whether I am going down the right path.

What do you guys think? Any ideas?

Thanks a lot in advance, I hope all the above makes sense :)

Luca

Thanks Casey, just wanted to get a second opinion on this one..

I am switching based on user id, not subdmain that's why :)

Hello,

I know that Rails uses a digest to secure session data, however I wanted to ask whether a better solution could be adopted.

I am currently loading the tenant in apartment.rb using a tenant_id session variable created after login in session controller (Devise).

Do you guys think this is safe enough? Wouldn't want someone to change the id and access other tenants data.

Cheers