Ruby On Rails

Wow,  Ruby On Rails take 2 for me was a long day.      I spent most of my time today working with 3 ubuntu server builds and various methods to install “ruby on rails”.  A few months ago went after install on some working LAMP stack dev systems and didn’t have much luck.  Today I started out with mindset of getting something working.  After 3(+) different online tutorials and 3 different test servers at Digital Ocean, I was able to get ruby and rails setup 3 different ways.   There are also ways to get ruby on rails 1 click from Digital Ocean.  Either way,  ruby on rails has many advantage over traditional  LAMP implementation but as far as setup goes, easy is best for me.  Especially when it comes to getting “html” working with an ip address or a “website”.

It’s too bad I did not find this link first:  https://www.digitalocean.com/community/tutorials/how-to-use-the-ruby-on-rails-one-click-application-on-digitalocean

In the terms of having a framework with plugins, gems, releases, git integration, relentless copies of filesets, rails is a very big platform to play around with. I aim to do just that.  My plans are to use rails and nodejs to solve some internet-age old problems with some of my side projects.  More to comes soon on this road to ruby on rails.

http://railsapps.github.io/installrubyonrails-ubuntu.html

https://gorails.com/setup/ubuntu/14.10

https://www.digitalocean.com/community/tutorials/how-to-install-ruby-on-rails-with-rbenv-on-ubuntu-14-04

https://www.digitalocean.com/community/tutorials/how-to-install-ruby-on-rails-with-rbenv-on-ubuntu-16-04

Day 2: 12.31.2016

Today I did a one click install ruby on rails server at Digital Ocean, got my app working as rr.bpm.digital(see #bpmdigital full post here),  and started adjusting to build a framework to deliver html and audio assets to a browser.  This ruby server has no connection to mysql, so it is going to be standalone, and expandable.  Before things got confusing I was able to create a flow chart  to outline the first/additional request nature:

and then after some time expanding the sample source:

screen-shot-2016-12-31-at-3-55-57-pm

A very nice player with some metatags care of my soundcloud sample urls:

screen-shot-2016-12-31-at-5-09-37-pm

With a very nice facebook share:

screen-shot-2016-12-31-at-5-10-38-pm

Day 3: 01/01/2017

Today I spent good bit of my morning finishing the bpm.digital submission system to the point of needing the new ruby share urls to work dynamically.  I then started building out the test rails_project so that it would dynamically include snippets of html I created from the demo src above.  Once i had this working I had to spend a lot of time messing around with trying file.exist type processing while writing html to those files if they did not exist.   Nginx/Unicorn seamed to struggle trying to access local file but could write them quite well.  I was unsuccessful at if(file.exists) as such and resorted to building through the issue and making each request lookup json from API and write the snippets for every request.   Later I will use a database connection (vs local file touching) to bypass over writing files.

By the end of the day,  I won many battles and have a few working samples:

screen-shot-2017-01-01-at-8-42-34-pm

screen-shot-2017-01-01-at-8-45-54-pm

Day 4: 01/02/2017

Today my goal was to cleanup all the automation and any manual processing I was using yesterday to get a new url to work turnkey.  Those 2 things were: making new image – saving mp3 id3 tags, resolving an issue “ruby on rails render partial fails when file exists” with the rails application.  To get the images and tags I created an API for getTags/[ID] ( a public wrapper for current Id3 tag processing crontab ), which would be called as the upload completes.  Next when you travel to the new url, rails hits the bpm.digital API getSong[ID] for a json wrapper of necessary information to save 3 asset files:

screen-shot-2017-01-02-at-2-08-46-pm

My app main concept was to save, then include these files, and for some requests it worked just great.  For others, seems to be random, it just did not pickup the files.  My solution to that was to store the contents of the file in an @globalAssetVariable before file is written, then rescue as raw(@globalAssetVariable).  For production I am going to need cached written file assets to load 100%, so what works for now, is not a large volume solution.   At first I thought it may be related to file data specific to certain uploads, but i was able to rule that out by copy files that didnt work, to /test/ route and they worked.

Now that the main system loop works,  it is time to make things more user friendly, add some error handling, and finish up some more finite tasks at the upload end (adding more u/i fields, more content into submit modal) and at the rails server (using more content, expanding basic template/framework).

Day 5: 01/03/2017

Today I spent more time finishing up the submission modal and making things work to get 100% of the data for a full url.  Some new data includes user provided hastags, the mp3 file’s id3 tags, and some new user provided links.  All of the necessary data is already provided  in my /api/getSong/[ID] and consumed into my rails app already.  I just need to improve the application markup to use the new information.  Should be a simple task with a working framework and all the right data.

And after a bit of massaging a working url with all of the data:

screen-shot-2017-01-03-at-1-23-12-pm

Will deal with making this pretty later, as well as adding embed, and maybe the AddThis widget.   I can see myself getting better at ruby already.  I am finding methods I need to search for fast in google and I am learning what files I can and cannot change without restarting unicorn.

Day 5: 01/04/2017

This morning I started right away to get the rails app working with postgres to insert a View for every url request.  Since this app is going to create itself from nothing, it is part of the applications initial behavior to create a Views database table, then insert the first record.  Once I had this basic concept down,  I was able to quickly make the same setup work for a Plays database.  I then created a route for /api/play and separate controller to handle posting the [ID].  This is where ruby shines as I am able to specifically say this is a POST only route.  To trigger this api call I attached a jquery click event to the play/pause button class.    When the title of that element is Play, the api will fire the call.   If a user hits play/pause 100 times, its going to make quite a few calls inserting the click actions.  With the automation processing from the micro db(s) (postgres) to the master db (mysql) I will run some accountability to rate limit the # of plays allowed per IP in the asset’s count columns.   Maybe those click junkies will get a lil ego boost seeing the short term counts go up.  Once automation runs that will set the official master count, and reset all micro counts to zero.     Once this was done I did a lil more work in the view, adding the counts, adding the fullsize image, and a play button that i used to test the click events.

Here is the current test view:

screen-shot-2017-01-04-at-11-46-35-am

 

Day 5: 01/10/2017

I ran the pages above inbox as an iframe similar to the one I have been using for soundcloud.  I got about 1700 views and 35 plays.  I took it off once I realized that the page seemed to be loading 4 copies of the audio. I pulled it out for the time being.  I need to look into that soon, but for now I have a need for these urls without a player.  In the last 5 days I have duplicated the current system and improved it for the remix platform.  Check that out here:

Remix Competition Platform – Code Race

Much of the login stuff will need to be part of rails application, but for today I need to make r1.bpm.digital/[CODE]/ work without a player.  I was going to try and use the same application but after a few major hinge points,  I decided to make a separate rails application on the same server for just for the remix urls.    It took me just a second to find the right nginx settings.  It took me much longer to get unicorn duplicated and running but after I got all the settings copied I now have a separate unicorn just for the 2nd application as “unicorn_remix”.  I need to restart the second instance of unicorn with “service restart unicorn_remix” and then added it to startup automatically.

Now the ubuntu ruby on rails server is hosting 2 different applications “rails_project” and “rails_remix”.  Now I can get onto customizing this url to be embedded and used on remix.bpm.digital.