Posts

Showing posts from 2016

Uploading profile pic using photofy gem

Hi fellas, Photofy gem is to provide simple method to do fileupload of pictures and provides getter setter methods of it and save on model object commit we are used of using paperclip and other gems. But it saves your effort from active record and other kind of stuffs. Include gem photofy in your Gem file. gem 'photofy' bundle install define photofy with the config in the model for which you want the file upload photofy(:avatar_image, {image_processor: Proc.new {|img| img.scale(200,200)}}) here after that you need to define your file upload attribute as: <%= f.file_field :avatar_image %> in the form where you want to upload the file after that in your action please whitelist your avatar_image attribute as: params.require(:users).permit(:name, :avatar_image)  Please be assure you have rmagick gem and imagemagick installed in your system. After uploading pic and submitting the form you will see a photofy folder will be created in app directory but

Integration of angular 2 tour of heroes with rails 5 api

Image
Hi fellas I know its been a hard journey of angular 2 tour of heroes but now once you are done with tour of heroes you may want it to integrate with Rails 5 api only application and to achieve that first you need a separate rails 5 api only application I have wrote a blog for rails 5 with hero resource just follow that and create a basic rails 5 api app with hero resource. http://nitanshu.blogspot.in/2016/08/initialization-of-rails-5-api-only.html In the json you see created_at and updated_at keys it will cause problems on the Angular 2 end since our app is only expecting the id and name attributes. Let’s take care of that right now since we’re already working on the Rails side. We’ll need to add the active_model_serializers gem to our Gemfile . gem 'active_model_serializers' bundle install mkdir app/serializers Create a new file called app/serializers/hero_serializer.rb with the following content. class HeroSerializer < ActiveModel::Serializer   att

Basic app in Rails 5 api mode

Image
  In Rails 5  you can create an app which will provide you only JSON API support. To do that actually there are two ways one is through rails gem and another is from git repo of rails I prefer rails gem: ================= First way(preferable) ================== To start with rails you need ruby version >=2.2.2 so first you need to install ruby-2.3.0 and rails 5 rvm install ruby-2.3.0 rvm use --default ruby-2.3.0 gem install rails -v 5.0.0 rails new my_app --api cd my_app rvm use 2.3.0 create a rvm wrapper for your application for that create two files one is .ruby-version and another is .ruby-gemset. In .ruby-version file type the current ruby version ruby-2.3.0 In .ruby-gemset file type the current ruby version @my_app now to initialize rvm wrapper cd .. cd - rvm current now you will see ruby-2.3.0@my_app bundle install ===================== Second way ===================== git clone https : / / github .com / rails / rails cd rails bundle in

Angular 2 basic terminologies

Transpiler : A source-to-source compiler, transcompiler or transpiler is a type of compiler that takes the source code of a program written in one programming language as its input and produces the equivalent source code in another programming language.   Decorator : Decorators are a proposed standard for ECMAScript 2016 by Yehuda Katz, to annotate and modify classes and properties at design time. This sounds pretty much like what annotations do right? Well… sort of. Let’s take a look at what a decorator looks like: // A simple decorator @ decoratorExpression class MyClass { } Wait. This looks exactly like an AtScript annotation! That’s right. But it isn’t. From a consumer perspective, a decorator indeed looks like the thing that we know as “AtScript Annotation”. There is a significant difference though. We are in charge of what our decorator does to our code. Taking the code above, a corresponding decorator implementation for @decoratorExpression cou

Injecting services in angular 2

Angular 2 applications can basically be written in any language, as long as it compiles to JavaScript in some way. When writing our application in TypeScript, we use decorators to add metadata to our code. Sometimes, we can even omit some decorators and simply rely on type annotations. However, it turns out that, when it comes to DI, we might run into unexpected behaviour when injecting dependencies into services. This article discusses what this unexpected problem is, why it exists and how it can be solved. Injecting Service Dependencies Let’s say we have a simple Angular 2 component which has a DataService dependency. It could look something like this: @ Component ({ selector : 'my-app' , template : ` < ul > < li * ngFor = "let item of items" > {{ item . name }} < /li > < /ul > ` }) class AppComponent { items : Array < any > ; constructor ( dataService : DataService ) { this

How to Deploy an Angular 2/Rails 5 App to Heroku

Initializing the App The first step will be to initialize a new Rails 5 project . I’m calling mine rails_5_angular_2_deployment_example . For the front-end we’ll use angular2-seed . Clone the repo into a subdirectory called client . (The name client , in this case, is important. If you call it something else, the deployment won’t work.) git clone git@github.com:mgechev/angular2-seed.git clie git clone git @ github .com : mgechev / angular2 - seed .git client We’re just interested in the angular2-seed code. If we keep it as a repository inside our project’s repository, there will be problems. Kill client/.git . rm -rf client/.git rm - rf client / .git Now install the Node packages. cd client npm install cd client npm install Before we try to deploy our app w