RoR 101: Session 6

686 views

Published on

Part 6 of 6

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
686
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
7
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

RoR 101: Session 6

  1. 1. Building Web Apps with Rails VI
  2. 2. Session 5 Recap <ul><li>User Model
  3. 3. Installing Gems with Bundler
  4. 4. Authentication with Devise </li></ul>
  5. 5. Session 5: Authentication <ul>At present, anyone can CRUD ( C reate R ead U pdate D estroy) </ul>Signed in Users Public
  6. 7. Session 6: Stocking Fillers... More on Assets AJAX Orphans! Your very own view helper
  7. 8. The Asset Pipeline NEW in Rails 3.1! “ A framework to concatenate and minify or compress JavaScript and CSS assets.” Also, enables CoffeeScript, Sass and ERB for assets. The default behavior in Rails 3.1 and onward is to concatenate all files into one master file each for JS and CSS.
  8. 9. Pre-Processing in Assets Asset helpers are available e.g. .class { background-image: url(<%= asset_path 'image.png' %>) }
  9. 10. The Asset Pipeline: Locations app/assets – your app's assets vendor/assets – not maintained by you lib/assets - maintained by you but not app specific public/ – old skool static location
  10. 11. What assets do we have? Shows assets available to application including stuff in gems. Rails.application.config.assets.paths
  11. 12. JS Assets Go to: 127.0.0.1:3000/assets/application.js In assets/application.js: //= require jquery //= require jquery_ujs //= require_tree . This is a sprockets manifest file.
  12. 13. CSS Assets Go to: 127.0.0.1:3000/assets/application.css In assets/application.css: // *= require_self // *= require_tree .
  13. 14. Cracking into AJAX
  14. 15. AJAX: Step 1 Add :remote => true to link_to 'Destroy', station, confirm: 'Are you sure?', :method => :delete
  15. 16. AJAX: Step 2 Add id to element in view <tr id = &quot;station_<%= station.id %>&quot;> Respond to javascript in controller respond_to do |format| format.html { redirect_to stations_url } format.js end
  16. 17. AJAX: Step 3 Keep id of the station to be removed. @remove_id = @station.id Define your response javascript: destroy.js.erb $('#station_<%= @remove_id %>').fadeOut();
  17. 18. Orphans! It's nearly Christmas, we should help...
  18. 19. Orphans! BY DESTROYING THEM.
  19. 20. Orphans! In station.rb: has_many :streams, :dependent => :destroy
  20. 21. Your Own View Helpers A Globally Recognized Avatar
  21. 22. Helper Files These can be found in “firstfm/app/helpers” Are included depending on controller.
  22. 23. Adding a Gravatar Helper require 'digest/md5' def gravatar_url_for(email) return &quot; http://www.gravatar.com/avatar.php ?gravatar_id= #{Digest::MD5::hexdigest(email)}&quot; end
  23. 24. Helper: Now use it in your view! Task! Using <%= gravatar_url_for(email) %> Display the gravatar for the currently logged in user!
  24. 25. Deployment with... &

×