Rails Dispatch

Rails news delivered fresh

Presented by Engine Yard

Hear what the experts have to say

And vote on your favorites!

How do I set up rails 3 to use jquery instead of prototype, ideally so the default javascript tag references jquery?

Asked May 05, 2010
Yehuda Katz answered
Answer

You need to do two things. First, remove the default JavaScript files from public/javascripts and replace them with jquery.js from http://code.jquery.com/jquery-1.4.2.min.js (as jquery.js) and rails.js from http://github.com/rails/jquery-ujs/raw/59dd91d945570391f905b1e40444e5921dbc2b8f/src/rails.js.

Next, do the following in an initializer

module ActionView::Helpers
  remove_const :JAVASCRIPT_DEFAULT_SOURCES
  JAVASCRIPT_DEFAULT_SOURCES = %w(jquery.js rails.js)

  reset_javascript_include_default
end
Answered May 09, 2010

Great screencast on the new action mailer.

One question though.

You used a default to setup a tracking timestamp.

Won’t Time.now only get evaluated when the class is loaded, so every email sent from a run of the server in a mode which doesn’t reload classes use the same timestamp.

Does ActionMailer allow you to pass a proc for default values so that they can be lazy evaluated?

Asked April 29, 2010
Mikel Lindsaar answered
Answer

On the using a default to track the timestamp, you are absolutely right and it was probably a bad example given that.

The proc idea is a great idea, so I just wrote a patch that implements this, it is now in the “Rails Github repository”: and look forward to it in the next rails release or by tracking Rails git in your Gemfile.

I also added the ability to call ActionMailer instance methods as well.

You would call it like so:

class Notifier < ActionMailer::Base
  default :from => "mikel@rubyx.com",
          :reply_to => "enquiries@rubyx.com",
          "X-Time-Code" => Proc.new { Time.now.to_i.to_s },
          "X-Special-Method" => Proc.new { my_method }

  def welcome_email(user)
    @name = user.name
    @message = user.message
    mail(:to => user.email, :subject => "G'day Mate!", 
      :sender => "system@rubyx.com")
  end

  private

  def my_method
    "This is some arbitrary string"
  end

end

The resulting Proc gets called ON generation of the Mail object, not when it is sent.

Thanks for pointing it out!

Answered May 02, 2010

Hey Rizwan,

Thanks for your article on rails routing.
I have a remark however. You’re all publicizing this new great router and it is great (both the fact that you’re publicizing it and the router).

However before to say out loud “you can route sinatra apps”, you should, I think, check that it effectively works.
Routing basic rack apps works. But routing sinatra apps it defunkt.

See my ticket on lighthouse : https://rails.lighthouseapp.com/projects/8994/tickets/4478-impossibility-to-mount-a-sinatra-app#ticket-4478-1

Cheers
Damien

Asked May 13, 2010
Rizwan Reza answered
Answer

Hey Damien,

Thanks for bringing this up. I can say that the way mounted Sinatra application worked has changed a bit. I agree that the article is not showing this way, since like you, I also think it needs to be fixed. But it seems you imply that we cannot mount Sinatra applications to Rails at all, which is definitely not true. I’ve generated a sample Rails application and pushed it to Github. Have a look: http://github.com/rizwanreza/sinatra-rails

The thing I would like to see get fixed is that we shouldn’t do match ‘/sinatra(/:string)’ => SinatraApp but rather match ‘/sinatra’ => SinatraApp and the Sinatra application should go on from there, as I detailed. This is how it worked before. I am going to ask Joshua Peek (who worked on Router) to let us know how we can fix this. We would certainly love a patch from you as well. :)

Thanks once again.

Rizwan

Answered May 13, 2010

I just read your piece on upgrading to Rails 3 and I was hoping you could address the deprecation warnings a little. Moving to Rails 3 will be my first Rails upgrade and as a result, I’m not sure how the Rails team handles these notices and where I should even look for them.

I think you guys are doing a great job of getting the community ready for Rails 3, I just thought it might be nice for a little write up on how these warnings will be displayed to the user and what we can do about them.

Thanks!
Jon

Asked May 23, 2010
Rizwan Reza answered
Answer

Hey Jon,

Rails 3 deprecates quite a few areas in favor of new and better ways of doing things. You might want to look at the log files to see what are the deprecation notices concerning the code you have. Also, the Rails 3 Changelog details them nicely: http://edgeguides.rubyonrails.org/3_0_release_notes.html

The core team cares a lot about how deprecation warnings are displayed, so you’ll get clear instructions on what needs to be changed to remove the notice.

Thanks!

Answered May 28, 2010