Showing posts with label learning ruby on rails. Show all posts
Showing posts with label learning ruby on rails. Show all posts

Oct 27, 2015

Error 2002 Can't connect through socket '/tmp/mysql.sock

Mysql can't connect '/tmp/mysql.sock


This is one common problem. The last time I experienced it was during installation on my macbook. There are plenty of good discussions to be found. In case you have not tried, there is an official coverage of this issue at the mysql website:

The error (2002) Can't connect to ... normally means that there is no MySQL server running on the system or that you are using an incorrect Unix socket file name or TCP/IP port number when trying to connect to the server. You should also check that the TCP/IP port you are using has not been blocked by a firewall or port blocking service. Source: dev.mysql.com

Can't even find the mysql-server package using yum? I have that covered here.

No package mysql-server available

No package mysql?

If you are wondering why you are getting this error "No package mysql-server available" after trying yum install mysql-server, here's why:

CentOS 7 has replaced MySQL with MariaDB. Source: Rackspace.

Solution

Do a `yum install mariadb-server mariadb` instead and be on your way!

Facing an Error 2002: Mysql can't connect '/tmp/mysql.sock? I've solved that here.

Oct 20, 2015

Can somebody please teach me Rails routing

Great Rails routing guide wanted


I have watched ALL the videos. You name it - youtube, egghead, mckenzie, free videos, paid videos - I still don't have a firm grasp of Rails routing.

By firm-grasp I mean being able to take an empty routes.rb file and start writing what I want to write to build the apps I plan to build. I find that with all the other videos, I still have to watch them while I write my own routes - so that sucks. Really.

May 16, 2015

Learn Ruby programming slowly

Every now and then I would be forced to go back to Ruby. I guess you cannot avoid having a solid ground to move up from :)

Found these to be somewhat more useful - compared to the likes of gorails, teamtreehouse, codeacademy or lynda.

May 12, 2015

Ruby on Rails 3 Tutorial by Derek Banas

Stumbled into this refreshingly comprehensive tutorial on ROR.

Created by Derek Banas - his videos are pretty decent.




May 9, 2015

To TDD or Not?

Here are some interesting discussions on TDD.

Pete's Write More Tests

Cedric's Pitfalls of TDD

Hacker news discussion - different than linked by Pete's writeup

Adron at Composite Code on Anti-TDD Arguments and Myths

rspec error messages

If you get this:

`require_relative': cannot load such file -- path (LoadError)


Do this:

Double-check that the files referenced by all your "require_relative" exist.
Also check that the spelling is correct and matches both ways.

If you get this:

Deprecation Warnings:

Using `should` from rspec-expectations' old `:should` syntax without explicitly enabling the syntax is deprecated. Use the new `:expect` syntax or explicitly enable `:should` with `config.expect_with(:rspec) { |c| c.syntax = :should }` instead.


Do this:

Replace "@book.should be_an_instance_of Book" with:

expect(@book).to be_an_instance_of Book

This is due to deprecation of the "should" syntax.

Learn rspec

I don't know TDD or BDD or rspec. All I know is you need to test your code.

According to the odin project:
Rspec is a domain specific language written in Ruby to help you test your Ruby code. Oh man, you can't use it if you ever move to Javascript or something else. Not universal I suppose.

But I haven't yet been able to get my head around "why you have to write tests before you code". How does that even work? I don't even know what I'm going to code yet or how the code will be written and ... I have to test it? Well, I'm going to spend time to understand this (view  all my reading on the matter here). Meantime, below are some resources I find useful and confusing.

Helpful resources:
Refurbished iPhones | JemJem

Confusing resources:

May 1, 2015

Using Bootstrap with Ruby on Rails

Getting started

This short tutorial will get you up, solved, and running with Bootstrap in your Rails app in 5 steps.

1. First, create your Rails app.

rails new demo-app


2. Include the bootstrap-sass gem by inserting this line into your Gemfile.

gem 'bootstrap-sass',


3. Run the bundle install command. You now have bootstrap-sass installed for your demo-app.

We are now going to edit application.js and application.css.scss at the locations below. If you don't have any of these files, simply create it. Example: touch application.css.scss

app/assets/
|-- images
|-- javascripts
|   |-- application.js
|   `-- tooltip.js
`-- stylesheets
    |-- application.css.scss
    `-- main.css.scss

4. In application.js, insert these lines:

//= require jquery
//= require bootstrap-sprockets
//= require turbolinks
//= require_tree .


5. In application.css.scss, insert these lines:

@import "bootstrap-sprockets";
@import "bootstrap";
@import "main";


( Note: We have @import "main"; because there is a main.css.scss file in the stylesheets folder. Otherwise don't include it. )


And you're done!

So now you can test that your app has Twitter Bootstrap properly installed by copying any of the Bootstrap components and pasting it into your index.html.erb file and firing your web server.

I particularly like Bootstrap's Modals because it works "properly". Once it pops up you can either click outside the Modal or hit the Esc button on the keyboard to close it. Improper or poorly designed modals won't close until you hit exactly on the modal's "close" button. Don't we all hate UI elements that force the user to follow its rules?

Oct 27, 2014

Sphinx Search WARNING: key 'sql_query_info' was permanently removed from Sphinx configuration. Refer to documentation for details.

I'm using Sphinx 2.2.5 and the gem Thinking-Sphinx.


Every time I run the command RAKE TS:REBUILD I will get the following warning messages. How annoying. You'd be pleased to learn that these warnings are harmless as they are due to deprecation.

WARNING: key 'sql_query_info' was permanently removed from Sphinx configuration. Refer to documentation for details.

WARNING: key 'charset_type' was permanently removed from Sphinx configuration. Refer to documentation for details.


WARNING: key 'enable_star' was permanently removed from Sphinx configuration. Refer to documentation for details.


Sep 21, 2014

cap production deploy errors

If you get this:

cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing on host my-app-name.com: git exit status: 2
git stdout: Nothing written
git stderr: fatal: Not a valid object name
tar: This does not look like a tar archive
tar: Exiting with failure status due to previous errors



It's probably due to deploy.rb attempting to deploy a branch that is empty on remote ie has not commits yet.

Solution: Try pointing to a branch with commits.

Aug 23, 2014

Setting Up Virtual Hosts With Apache 2.4.6

I've got two servers - one running Apache/2.2.15 (Unix) sitting on Cent OS version 6 and the other running Apache/2.4.6 (CentOS) sitting on Cent OS version 7. These two versions require very different approaches to setting up virtual hosts and to managing Apache itself.

For 2.4.6, the configuration file is located at /etc/httpd/conf/httpd.conf

Previously in 2.2.15 you would configure namevirtualhosts in this httpd.conf file.

The virtual hosts settings in 2.4.6 are set in the vhost.conf file located at:
/etc/httpd/conf.d/vhost.conf

You no longer include "namevirtualhosts" in your config. If you do you will get this message:
AH00548: NameVirtualHost has no effect and will be removed in the next release /etc/httpd/conf.d/vhost.conf:1

The virtual hosts settings themselves remain unchanged and would typically look something like this:
<VirtualHost *:80>
    ServerAdmin admin@domain.com
    DocumentRoot /var/www/yourapp  
    ServerName yourdomain.com
    ServerAlias www.yourdomain.com
    ErrorLog /var/www/logs/error-log
    CustomLog /var/www/logs/access-log common
</VirtualHost>

Restarting Apache would be via "service httpd restart" in 2.2.15.

In 2.4.6 the command is now "systemctl restart httpd."

Syntax checking is still via "httpd -t". Apache recommends httpd -S which gives you expanded information.

Official 2.4.6 page [Link.]

Official current version page [Link.]

Aug 16, 2014

Books

"Agile Web Development with Rails 4" shows you step-by-step how to build an online store using Ruby on Rails 4.

Errata from my own experience below. Full errata here.

//= require jquery-ui/effect-blind (works, in Iteration F3)
//= require jquery.ui.effect-blind (doesn't work)

Aug 13, 2014

Server setup

It's essential to have access to a linux server to learn Ruby and Rails. So get one at Digital Ocean or Linode. It's perfectly OK to start with the $10 per month option or $5 with Digital Ocean. Or you can use it by the hour and pay pennies instead! 3 hours on Digital Ocean costs me $0.03.

Building an online store means I'm going to need to know how to work with Linux, Mysql database, and Apache web server at minimum.

My project is built on CentOS 7. I'm using Mariadb for database (apparently CentOS 7 doesn't allow you to install mysql any longer).

Locally I have a Macbook (2012 Macbook Pro) which I use to connect to the server and write Ruby/Rails code. I have Sublime Text (it's set up to upload code to server every time I hit "save") and use Github's Atom text editor to code, Adobe's bracket to push to repo, and iTerm (a terminal-like app).

When is it a good time to buy a mac? Use this guide.


I need to build an online store

I decided to take on Ruby on Rails head-on. I need to build an online store.

I have hired some developers from oDesk in the past (none of them got my plans to 100 percent). I once hired a programmer I found through a conversation in Quora (this too didn't get me ideas off the ground). So after spending some $8,000 over a span of just under three years, I came to the conclusion hourly developers will "always" push for the next hour or batch of 8 hours (a day's work) and you'd be powerless to do anything about it unless you know how to read code. And the truth is you can always (always) do better with a solid plan ie work scope.

I've paid 2 different developers $200++ separately in oDesk to get a csv file upload feature so I can put my product catalog from Excel into my online store's database. Do you know how long it took me to build this feature in Ruby on Rails myself? Under 10 minutes!

So I'll be sharing this journey and distractions here.

Sites mentioned: oDesk, Quora.