day 129 — code 365
Tue 19 Apr 2016
WDI Week 9 (Day 42)
What we did today:
- Project 2
We spent today working on our projects again. Here are some of the things I learnt:
Regardless of which branch I’m in, if I do:
git push origin master
I will ONLY push the master branch to GitHub.
If I want to push a branch to GitHub,
git push origin local-branch-name
Git will search for the remote branch with the same name.
Its’s good to work on branches locally. Make sure it works. Merge locally. Then push.
However, branches can also be shared, by pushing branches to GitHub.
It’s helpful to inspect Rails forms in view-source. This is useful for looking at the name attribute for inputs — as this is how the input values will be stored (and accessed) by Rails.
Can only set POST / GET on a elements when the page loads (can’t set it afterwards using jQuery).
Or, I can write my own AJAX request…
code.to_sql will show the actual SQL request!
@goals = Goal.where(:acceptor_id => nil) && Goal.where.not(:initiator_id => @current_user.id)
This won’t work. Ruby will use logical operator logic, and evaluate the Right Hand Expression only. We can test this in Rails Console.
Goal.where(:acceptor_id => nil) && Goal.where.not(:initiator_id => @current_user.id).to_sql
"SELECT \"goals\".* FROM \"goals\" WHERE (\"goals\".\"initiator_id\" != 3)"
What I wanted to do is achieved with this:
@goals = Goal.where(:acceptor_id => nil).not(:initiator_id => @current_user.id)
By chaining the methods together!
However, we ended up with problems when chaining where and where.not
What we did instead:
Goal.where(:acceptor_id => nil) - Goal.where(:initiator_id => @current_user.id)
Using the Ruby array method!
And then we forgot to assign the current user to newly created goals.
We tried to fix this by doing this:
@goal.initiator << @current_user
But this didn’t work, because we should do an assignment:
@goal.initiator = @current_user
Then we had to destroy all the goals without an initiator:
Goal.where(:initiator_id => nil).destroy_all
Our local images are not loading — our logo asset is showing as a broken link in our header. Not pretty! We’ll have to fix this tomorrow.
Heroku does not like binding.pry, nor require ‘pry’ — these must be removed from all code pages, or else the app will crash.
A scattered medley of things I learnt… thanks for stopping by!