RoR 101: Session 6

  • 276 views
Uploaded on

Part 6 of 6

Part 6 of 6

More in: Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads

Views

Total Views
276
On Slideshare
0
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
3
Comments
0
Likes
0

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. Building Web Apps with Rails VI
  • 2. Session 5 Recap● User Model● Installing Gems with Bundler● Authentication with Devise
  • 3. Session 5: Authentication At present, anyone can CRUD (Create Read Update Destroy)Signed in Users Public
  • 4. Session 6: Stocking Fillers... More on Assets AJAX Orphans! Your very own view helper
  • 5. 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.
  • 6. Pre-Processing in Assets Asset helpers are available e.g..class { background­image: url(<%=  asset_path image.png %>) }
  • 7. The Asset Pipeline: Locationsapp/assets – your apps assetsvendor/assets – not maintained by youlib/assets - maintained by you but not app specificpublic/ – old skool static location
  • 8. What assets do we have? Rails.application.config.assets.pathsShows assets available to application including stuff in gems.
  • 9. 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.
  • 10. CSS Assets Go to: 127.0.0.1:3000/assets/application.css In assets/application.css:// *= require_self// *= require_tree . 
  • 11. Cracking into AJAX
  • 12. AJAX: Step 1 Add :remote => true tolink_to Destroy, station, confirm: Are you sure?, :method => :delete
  • 13. AJAX: Step 2 Add id to element in view   <tr id = "station_<%= station.id %>"> Respond to javascript in controllerrespond_to do |format|  format.html { redirect_to stations_url }  format.js end
  • 14. 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();
  • 15. Orphans!Its nearly Christmas, we should help...
  • 16. Orphans!BY DESTROYING THEM.
  • 17. Orphans!In station.rb: has_many :streams, :dependent => :destroy
  • 18. Your Own View Helpers A Globally Recognized Avatar
  • 19. Helper Files These can be found in “firstfm/app/helpers”Are included depending on controller.
  • 20. Adding a Gravatar Helperrequire digest/md5def gravatar_url_for(email)  return  "http://www.gravatar.com/avatar.php ?gravatar_id= #{Digest::MD5::hexdigest(email)}"end
  • 21. Helper: Now use it in your view!Task! Using<%= gravatar_url_for(email) %>Display the gravatar for the currently logged inuser!