The fellows over at Err have finally seen the light of jQuery. My first thought is welcome to the party, we’ve been wondering when you’d get here. From my first days with rails, I’ve been using jQuery over Prototype. Why? Well, a lot of reasons, but the biggest one is because […]
Everyone loves before_create and before_save. Recently it came in very handy for logging hits to objects. If the user is logged in, I want to store the user’s full name and the user’s type, otherwise, keep those null. So I added this to my PostHit model:
def before_create
if self.user
self.user_name = […]
There is this helpful method I’ve been evolving in my apps for a bit, it’s called render_either and it goes a little something like this: (in application.rb)
def render_either(opts = {})
# For MIME:Type Recognition
# respond_to do |f|
# f.js {@wants = […]
I previously discussed the difference between flash.now[:notice] and flash[:notice]. I ended with a summarizing rule that says when you end an action with render, you generally want to use flash.now[:notice], and when you end an action with redirect, you want to use flash[:notice]. While simple, I hate remembering that rule, and what really complicates things […]
You’re just starting on rails and you’re very excited about the ease of flash[:notice]. But every now and then, you set a flash notice and it seems to follow your clicks to the next action when it shouldn’t. Why? I’ll tell you.
Intro to flash[:notice]
flash[:notice] belongs to FlashHash.The basic use of the flash hash […]
In my Rails controllers, I have a lot of this:
@project = Project.find(params[:project])
if @project
@project_product = @project.project_products.create(params[:project_product])
if @project_product.valid?
# Do something with success
else
# Do something with error
end
else
# Do something with error
end
The thing that I don’t like about that style is that the […]