See the http://therailsway.com/
#railsway on irc.freenode.net for questions at the end of the presentation.
class TheRailsWay < BLog
Instead of teaching you how to build things in Rails, Jamis and Koz will show us they things should be built.
class Expense < ActiveRecord::Baseprotected def mate_created_now_if_created_today if self.created_at Time.now.beginning_of_day
self.create_at = Time.now
john.documents #use this Document.find_all_by_user_id(john.id) # instead of this
@john.documents.find(:all, :conditions=>[“title like ?” “koz”] # use this
Document.find(:all, …) # instead of
#This becomes even easier to read when the search conditions become more elaborate,
#i.e. Find all documents by john tagged with ‘cool’?
#This should be coded as
Document.find(:all, …) #instead of using with now much more conditions .
#Even better add a method explicating the association:
#But just use one, don’t repeat yourself.
#You can get fancy you can use assosciation extensions:
- Dont’ use of !!
- use. More intention revealing
@account_code ? true : false
returning new do |billable|
blillable.booking = Book.build_with_assocations
- some code omitted…man, the speakers are going to fast for my typing!
Now onto some QA.
Q: Is the code from the code gonna be posted?
A: Yes, on the website.
Q: In the Account code example, could you use @account_code.
A: That would test something different as an empty string would return true. It depends on the requirement.
Q: Guidelines or best practices for overriding to_param?
A: If you want prettier Urls you can provide a to_param. Otherwise don’t bother.
A: returning passes an object to a block and returns the object.
Q: Cascading validations?
A: Validations can be tricky in that case. They don’t have a best practices to present on that right at this moment. But don’t worry about that too much.
Q: Koz. Can you clarify what’s the context key is (in the routes)?
A: Forces a params[:context] = “www”
Q: How long does it take to do a typical RailsWay articles
A: 1 day or 2. But it depends.
Q: has_many : through. What about multiple : through? I.e. A through B through C through D?
A: I.e. A give me all yours Ds? If you really need it…add a custom method to the top.
Q: Attributes on join tables and conditions? Multiple associations? I.e has_many and has_one_current (through)
A: I.e. document has_many versions, current_version. Implementation doesn’t really matter, but if current_version has business meaning make it an explicit method.
Q: What is your advice on keeping a database column private? I.e. a Model cannot access a column.
A: We don’t see much value in that. Document this to not “touch” this. But try to find a solution. This can be difficult has private methods can be circumvented by send. Just make it explicit.
Q: Final words of wisdom?
A: The RailsWay has been a little quiet, but now that the conference has been wrapping up, we will dive back into it.
Q: How do you answer questions that relate to deprecated features?
A: We try to keep it to Rails 1.2.
by Charles Nutter and Thomas Enebo JRuby Core Developer, Sun Microsystems.
Enterprise can be “doing cool new things and cool new ways”.
list = ArrayList.new
tar xzf jruby.tar.gzcp -rp ../goldspike vendor/plugins jruby -S rake war:standalone:create
jruby -S gem rails -y
jruby -S gem install gem_plugin
jruby -S gem install mongrel
jruby -S gem install activerecord-jdbc -y
cp lib/mysql.jar jruby/lib
if RUBY_PLATFORM =! /java/
require ‘jdbc_driver’ #I missed the proper code!
jruby script/generate migration entry
jruby -S rake db:migrate
# they continue to use the Rails generators and add standard Rails code
# Assemble a .war file that deploys your Rails application as a standard J2EE application.
http://localhost:8080/buggy/entries/list # Rails via J2EE