Tag: Rails

  • Better assert difference?

    Rails come with some awesome assertion methods for writing tests: assert_difference(“User.count”, +1) do create_a_user end That asserts that the count of user was incremented by one. The plus sign is not needed, that’s just an integer, I add it to make things clear. You can mix several of this expressions into one assert_difference: assert_difference([“User.count”, “Profile.count”], […]

  • Redirect to SSL in Rails applications

    I’ve looked at the various ssl_requirement repositories out there. I concluded the most modern and maintained version is yardstick’s which is released as a gem called sslrequirement, but I’ve failed to use it properly. So I just did it by hand. First, we need a simple method that will let us know whether SSL is […]

  • Really resetting the database

    When I start coding a Ruby on Rails project, I find myself modifying the migration files over and over. I know this is not the way they were intended to use, but to avoid upfront design, I only ad fields when I need them. If I respected the way migrations were intended I would end […]

  • My Profile page: a RESTful single resource using Formtastic

    I’ve just implemented the My Profile tab for Sano: Can I write 500 words about? Well, I can try. I like using RESTful routes. In case you don’t know what they are let me try to explain it quick, at least the relevant part. You normally have a set of route rules that would point […]

  • I love to code

    I said I was done for the day more than 6 hours ago, but I love to code, I couldn’t stop. I wanted to implement a small feature: make the creation of new weights simpler for the common case and I did it: Note: That change is not yet deployed. I don’t play with servers […]

  • Sano is open for business

    I really wish I was able to get farther in one day, but I think it’s good enough that I went from idea to deployed app. On retrospective I wasted too much time figuring out formtastic. I don’t regret doing it because it was in my TODO list and in the long run it should […]

  • Super Exception Notifier

    I like knowing when something goes wrong with my web apps, so I’m using Super Exception Notifier to get by email a report should any exception be raised in the app. If you go to Super Exception Notifier’s site you’ll see some instructions on how to add it to your project. This is how I […]

  • Merging users

    Remember that I said that when you log in, your ghost user has to be merged with the real user? Well, this is the code for doing it: class User < ActiveRecord::Base #… def merge(user_id) if user_id != nil user = User.find(user_id) user.weights.each do |weight| weight.user = self weight.save end user.destroy end end end The […]

  • Simplifying the weight CRUD

    After a rather long fight with formtastic I have a better CRUD for weight: But now that I think about it, there shouldn’t be a measured at in this view. That should be in an advanced new-form.

  • Creating the weight model and scaffolding

    With one command line I’ve created the weight model and the scaffolding, a fully functional CRUD little app without my Rails app. I know all Rails developer are rolling eyes now; but I still think this is awesome. It gets you up and running so fast: ./script/generate scaffold weight user_id:integer weight:float timestamp:datetime exists app/models/ exists […]