Skip to content

Instantly share code, notes, and snippets.

View morganwildermuth's full-sized avatar

Morgan Wildermuth morganwildermuth

View GitHub Profile
@morganwildermuth
morganwildermuth / rails_views_partials
Last active December 24, 2015 21:09
Preliminary intro to views and partials
Generally speaking, the controller will be pointing towards a view using either render or redirect_to:
1. render: tells Rails which view to show; doesn't run target action's code
2. redirect_to: tells Rails that the browser needs to send a new request to whatever the redirect_to value is; runs target action's code
Render vs. redirect_to can be confusing; here's a clear snippet of code from the Ruby on Rails Guide that should clarify
'''
def index
@books = Book.all
=Navigating=
visit('/projects')
visit(post_comments_path(post))
=Clicking links and buttons=
click_link('id-of-link')
click_link('Link Text')
click_button('Save')
click('Link Text') # Click either a link or a button
click('Button Value')
@morganwildermuth
morganwildermuth / gist:6546834
Created September 13, 2013 04:37
Active record legislators
https://github.com/morganwildermuth/ar-sunlight-legislators
class Vehicle
attr_accessor :status
attr_reader :gas_chance
attr_writer :color
def initialize(args)
@color = args[:color]
@wheels = args[:wheels]
@gas_chance = args[:gas_chance]
end