Getting Up & Running on the100.io
- git clone
- gem install bundler
- bundle
- errors galloreee http://cl.nicoll.co/duQZ
- google
rmagick Could not create Makefile due to some reason
brew install imagemagick
gem install rmagick -v '2.15.2'
bundle
- created and added all the secrets to .env.development
- rake db:create
- rake db:migrate
- rake db:seed (running seed data so you dont start with a blank db)
- rails s
js & ruby relationship #
You cannot talk to the front end with ruby. Otherwise, all other functionality falls to ruby in a js, ruby application.
Decrypting this erby line #
This line in erb looks super daunting…
<li><%= link_to "NORMAL", reset_font_user_path(current_user), method: 'post', remote: true %></li>
but really, in plain english, it is just doing this:
<li><a href="<%= reset_font_user_path(current_user) %>" data-method="post" data-remote="true">NORMAL</a></li>
link_to
is a ruby method that we are calling in our erb file. Don’t you just love short cuts?!
reset_font_user_path(current_user)
is being called by our href, it is a route. Anything with _path
is going to be a route. We also are passing the current_user to this route. What goodies doth enstow us in the route file, I do wonder?
resources :users do
member do
...
post 'decrease_font'
post 'increase_font'
post 'reset_font'
end
end
Method Post: Change data
(should probably have been a put, but hey it is in production and works)Remote True: Silently run an action
reset_font_user_path(current_user)
> /users/1/reset_font
Controller #
reset_font should match an action in the users controller:
...
def reset_font
current_user.update_attributes(font_size: 0)
respond_with current_user, template: 'users/font_change'
end
This action also needs to respond with whatever format is appropriate. Since we are calling this with remote true, it needs to respond with js.
If we did it normally with no remote: true
then we would need to respond with html. If we did it with json
then we would need to respond with json, etc…
With the new-ish rails however, these things do need to be whitelisted at the top of our routes:
respond_to :js, :html, :ics, :json
The old way would look something like this:
def reset_font
current_user.update_attributes(font_size: 0)
respond_to do |format|
format.js { template: 'users/font_change' }
end
end
This just in #
We could have simply done this -_-
/users/<%= current_user.id %>/reset_font
What the fluff is wrong with ruby people?! I swear they just do things to confuse the hell out of us plebeians (spelling?).
Need to double check your routes? #
http://localhost:3000/anythingthatsnotaroute
reset_font_user_path POST /users/:id/reset_font(.:format) users#reset_font`
- written by speedogrl