Driving out belongs_to and has_many

Here’s one way to do it:

  1. Set up the model_spec.rb file first. We’re going to use recipes and users for an example
  2. Add associations to the models recipe.rb and user.rb
  3. Create the migration and apply it.

Wanna see some code? Click through…

Posted in testing | Tagged , | Leave a comment

Devise users code kata

Devise is pretty spiffy, what with handling authentication 1-2-3. However, you still need to handle the users, and this code kata is exactly what you need.

The kata looks about like this:

  1. Do the Rails thing
  2. Do the Devise thing, install the views, etc.
  3. Install cucumber-rails
  4. Add session.feature
  5. Add session_steps.rb
  6. Add a resources :users (or resources :members or whatever) to config/routes.rb.
  7. Install rspec-rails
  8. Add controller spec
  9. Add routing spec
  10. Add view spec
  11. Iterate until everything passes

There’s a fair bit of code involved in this one…

Posted in rails | Tagged , , , , , | Leave a comment

Social Media Buttons for Rails Applications

Here are some small snippets of code for your Rails social media button pleasure:

First, the haml template:

%ul.cf.social_links
  %li#twitter
    %a{:href => "http://twitter.com/home?status=Check%20out%20the%20Portfolio%20Project%20-%20#{request.url}"}
      = image_tag('twitter.png', :alt => 'Share this on twitter', :title => 'Share this on twitter')
  %li#facebook
    %a{:href => "http://www.facebook.com/sharer.php?u=#{request.url}&t=PortfolioProject", :target => "blank"}
      = image_tag('facebook.png', :alt => "Share this on facebook", :title => "Share this on facebook")
  %li#linkedin
    %a{:href => "http://www.linkedin.com/shareArticle?mini=true&url=#{request.url}&title=Check%20out%20Portfolio-Project.com&source=#{request.url}"}
      = image_tag('linkedin.png', :alt => "Share this on linkedin", :title => "Share this on linkedin")
  %li#gplus
    .g-plusone{"data-count" => "false", "data-size" => "small"}

I bet you want to style it, too. Click, then.

Posted in rails | Tagged | Leave a comment


dool.in