Skip to content

Instantly share code, notes, and snippets.

5.1 maps to CS169 v13 w6l2s1 (YT) 5.2 (Third-Party Auth) -- maps to CS169 v13 w6l2s3 (YT) 5.3 (Single Sign-On, OAuth) -- maps to CS169 v13 w6l2s5 (YT) 5.3 cont. (Associations & Foreign Keys) -- maps to CS169 v13 w6l2s6 (YT)

I believe these vids are available on YouTube.

Every model has an errors object that tracks errors on your object which is especially useful to see what validations failed and provide helpful messages (notices) to the user -- V5.1,5:00.

V5.1,7:06 Callbacks.

###Including JS in search.js or application.js

jQuery works when inline in the view file, but not when added to the javascripts/ directory.

$(this) vs event objects

What's the difference.

####Strange Test Behavior

With no apparent order, the test will sometimes pass and sometimes not pass.

~/Desktop/coding_resources/programs/md_notes
23:36:02 davemox@Daves-MacBook-Pro $ bundle exec rspec
.........................................

Finished in 6.33 seconds
= link_to "Tags", tags_path
= link_to "Search", new_search_path
= simple_form_for @note do |f|
= f.input :title, label: false, placeholder: "note title"
= f.input :content, label: false, placeholder: "note content"
#tags
- @tag_list.each do |tag|
= button_tag "#{tag.name}", data: tag.id
#new_tags
= text_field_tag 'new_tags', nil, placeholder: "Add additional comma separated tags here"
~/Desktop/coding_resources/programs/md_notes
12:17:05 davemox@Daves-MacBook-Pro $ bundle exec rspec
..F..................................F...
Failures:
1) Add a new note create a note and create tags
Failure/Error: expect(page).to have_content "Postgres DB"
expected to find text "Postgres DB" in "Note created Tags Search Rails Ruby Postgres Rails, DB, Query"
# ./spec/features/note_spec.rb:42:in `block (2 levels) in <top (required)>'

####Zurb Foundation See this article. Good discussion of Foundation vs Bootstrap. Thought this was a great overview of responsive design.

####Mobile emulator Any tools you use to mimic different screen sizes? Mobile and tablet.

####Form submits to TagsController#destroy

Whenever I add the Foundation button-group to my form, the 'Save Changes' submit button requests TagsController#destroy instead of #update.

= simple_form_for @tag do |f|
  = f.input :name, label: false
  = f.button :submit, "Save Changes", class: 'button'
= link_to 'Back to Tags', tags_path, class: 'button'
= button_to 'Delete Tag', tag_path(@tag), :method =&gt; :delete, data: { confirm: 'Delete Tag?' }, class: 'button' 

Availability of set_user

Think I'm missing something obvious here, but why is set_user available to be called wherever I want in CollectionsController?

2.0.0p353 :009 > class Test
2.0.0p353 :010?>   def self.method1
2.0.0p353 :011?>     method2
2.0.0p353 :012?>     end
2.0.0p353 :013?>   def method2

Steps

Add to Gemfile

rails g devise:install

Manual Setup

  • action_mailer default url options in config/development.rb and config/production.rb
  • Add and use figaro gem to handle ENV variable for config/production.rb
  • ensure root is defined in routes.rb
  • ensure flash messages are available in app/views/layouts/application.html.haml.

Copy Devise views to app for editing

rails g devise:views

Testing controller 'helper' type methods

I have a couple methods defined in controllers that I call in one of the controller actions.

Example from SearchController:

I've been testing these methods by actually making a request. That can't be the most efficient way to test them. I can't exactly call ApplicationController.assigns_session_tags and then test the result...