Friday, 3 April 2020

Interactor in Rails

What is interactor?


Interactor provides a common interface for performing complex user interactions

An interactor is a simple, single-purpose object.

Interactors are used to encapsulate your application's business logic. Each interactor represents one thing that your application does.

Context

An interactor is given a context. The context contains everything the interactor needs to do its work.

When an interactor does its single purpose, it affects its given context.
Adding context

context.user = user


Example of interactor

class AuthenticateUser
  include Interactor

  def call
    if user = User.authenticate(context.email, context.password)
      context.user = user
      context.token = user.secret_token
    else
      context.fail!(message: "authenticate_user.failure")
    end
  end
end

Monday, 2 March 2020

RuboCop In Rails

RuboCop

A RuboCop is used in Rails best practices and coding conventions. It will make your code in good standard format. it will suggest you the best option to refactor your code in your rails application.


Installation

gem install rubocop-rails


Usage

You can run rubocop in your terminal. You can see the changes in yours console.

$ rubocop

Sunday, 9 February 2020

Create React App in linux system

Creating React Application

To install react run
$  sudo npm install -g create-react-app

Install nde dependencies
$  sudo npm i -g npx
$  sudo apt install nodejs-legacy
$  sudo npm install

Check the below items are installed in your system
$ node -v
$  npx -v
$  npm -v

Install latest version of node
$ sudo npm install -g n
$ sudo n stable

Create the react app
$ npx create-react-app rajfirstreact

Go to the app folder
$ cd rajfirstreact

Run  the react application
$ npm start

You can see your react application running in port 3000
http://localhost:3000

Thursday, 30 January 2020

MailCatcher for Development mail checking in Rails

MailCatcher runs a super simple SMTP server which catches any message sent to it to display in a web interface. Run mailcatcher, set your favourite app to deliver to smtp://127.0.0.1:1025 instead of your default SMTP server, then check out http://127.0.0.1:1080 to see the mail that's arrived so far.
  1. gem install mailcatcher
  2. mailcatcher
  3. Click on http://127.0.0.1:1080
Add the below code in environments/development.rb

config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = { :address => "localhost", :port => 1025 }
You can trigger any mail then it will display immediately.

Interactor in Rails

What is interactor? Interactor provides a common interface for performing complex user interactions An interactor is a simple, sin...