Getting Up & Running on the100.io  

  1. git clone
  2. gem install bundler
  3. bundle
  4. errors galloreee http://cl.nicoll.co/duQZ
  5. google rmagick Could not create Makefile due to some reason
  6. brew install imagemagick
  7. gem install rmagick -v '2.15.2'
  8. bundle
  9. created and added all the secrets to .env.development
  10. rake db:create
  11. rake db:migrate
  12. rake db:seed (running seed data so you dont start with a blank db)
  13. 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`

Want to Contribute? Contact mlapeter #
 
6
Kudos
 
6
Kudos

Now read this

Announcing Support For Multiple Games

Exciting news: We’re making some big changes to support multiple games! There’s more coming, but the first change you can see now is a “Games I Play” section at the top of your edit profile page: Group mods also have a similar option on... Continue →