Save 36% for Black Friday! Learn more

Ali Ahmed

Joined

1,020 Experience
0 Lessons Completed
1 Question Solved

Activity

Thanks Chris for clarity.

Hi, my question is simple that sometimes I have to extend my model with methods that are usually for more advance business logics and sometimes I need some methods that are used in views (not specifically helpers), I believe the former can be named as decoraters and latter can be called as presenters. However, I know there's a gem named draper which has examples of only I GUESS the presenters, even tho its naming convention follows Decorators, but I need advice or ensure if I could use the same gem to make both decorators as well as presenters objects.

Because I am always confused if I have to create another presenters directory in my app folder and write presenters there or just do it in the existing decorators directory (from draper gem).

Thanks Chris, expected answer with clarity. Appreciate it sir.

However, one minor gotcha that I am looking forward to come up, that how do I make sure that my model is always updated with new values from that API?

Let's say API now returns new results and my before_action hook only checks that if the model either exists or not with the value. How would I know if I have to hit the API again on each request and compare, maybe the timestamp attribute or, any others attributes that reflect that there now new results and then I now have to update the model.

Is there any easy logic in your experience?

Is it a good practice if we can call a REST api on before_action hook of application_controller.rb and store the response in helper method?

My Scenario is that I wanna call an API from another app and get its data for a specific user role after that user is signed in. I am using Warden gem and I also have its after_authentication hook to do that but how do I make sure to use that API response in my app (i.e helpers/views/controllers etc).

I am having a bad feeling to do it on every request, I need to know if there could be a pattern or any better approach that solves these kind of problems.

Posted in Can two apps consume webhooks of each others

So let's say I have two apps with different dbs and both are dependent to each other (feature wise). For example App #1 has the user table and App #2 calls the App #1 Sign In Api to login the user over here. To make communication back and forth b/w two can be done thru API and webhooks and it can work fine if App #2 updates the App #1 thru webhook and App #2 can call the APIs exposed from App #1 or viseversa. But sometimes it is required that both App #1 and #2 need to update each other some way.
So my question is can we setup webhooks on both end of the apps?
Meaning that generally Webhooks are usually provided by Service Providers and clients use them (i.e who have provided their callback URL to them) but is this also a possibility/good practice if we can provide webhooks from both of the apps and both can use use each others events to perform operations? e.g App #2 sends events to App #1 to update user profile and App #1 sends the same event to App #2 because both of app have User model with same fields and we'd need to make sure that data is always updated.

Posted in Rails + Stimulas or Rails API + React

Hi Chris

I have worked on many Apps with different set of architectures but never find this case at inceptive period that which approach we might choose to scale our Rails app either from being a server rendered app to become an API app and support Client Frameworks or make a Rails API backend that can serve Web and Mobile Front End both.

I have two scenrios to outline my Question:

  1. (Confusion) that to do a fast pace development of your startup, you can go ahead with Rails + (Our New Stimulas). But what if you feel, later or at initial level, that you might need to support your app on mobile platforms. What would the best way to start your project with?
  2. Even if I don't have to think too far ahead because trying to optimize for the later state has the potential to slow down the initial development and that's is for sure. Then, as a Rails Engineer, how facile it would be to get a Mobile app?

Since ActiveStorage released in a very recent version of rails. I faced a lot of issues when I had to play with it customly. I checked a lot of PRs and tried to contribute. Many of them are only in Edge Guides, based on master@241bbf2. Any ways, active storage works with having separate entities in your db with two tables blobs and attachments. When ever we attach items to model it associates the model with ActiveStorage::Attachment model and stores the file object in to the ActiveStorage::Blob model. I reckon that what if you initially attach a default image to user's object on the first time when the user is created. You can set the image in a method in your User model and do this (if you know already):

self.image.attach(io: File.open(Rails.root.join('app', 'assets', 'images', 'placeholder-icon.png')), filename: 'default-image.png', content_type: 'image/png')

and setting this in your before_create callback.

Hope this helps. I know there could be a better way in contrast to mine but this will set a default image nevertheless of having the traditional helper methods approach.

Posted in Need a Best CMS for Rails App Landing page

Hello Guys,

I am trying to have a CMS in my rails app that should be very easy to implement and very flexible so that site users can do messing with the content/styling of different pages. I did some research and found Locomotive quite useful but I haven't used it neither digged very deeply into it yet also I am not aware of the complexities it has. Any one with the experience, please advise.

Besides, I would love to know that how gorails.com CMS has been created, is it like customly built to manage pages or any open source platform used like locomotive etc. Basically, my purpose here is to have a CMS on my site just like gorails.com (maybe) which should allow different users of my site (such as Admin Users) to manage the content and styling of my app's landing page.

Your frequent response will be very appreciable.

Thanks.

Posted in How to build REST APIs?

Hi Chris

Yesterday I was just wondering that how can I build an app which follows REST principles. I searched on many articles and they are in too much nitty-gritty with less examples of how to create a REST controller.
I really need to understand the core concepts of REST APIs. Can you please make a new screencast on this and I am sure that it will be really really helpful in the rails community.

Thanks