Rails Notes

I got interested in Rails a year or so ago when I first started hearing the hype, and I dug into it a little bit.  At the time, I came to the conclusion that while the Ruby language was pretty slick, Rails itself was basically a code generation engine that would become more hindrance than help on a real project.

Recently I started in on a new little side project and decided to give Rails another chance.  This time around, I followed along with a book, Ruby on Rails: Up and Running, which isn’t a great book, but for someone who is already marginally familiar with Rails, it serves pretty well.

Up and Running made a couple of things clear to me.  One is that the power of Ruby is in it’s O-R mapping, Rake migration, and ActiveRecord.  I also discovered script/console.

The script/console script gives you an interactive command-line inside your application. You can create model objects, execute methods on them, and see the results interactively.  For example, in my model I have a User, a Log, and a LogLine.  I can explore these objects and their relationships in the console:

[butler]$ script/console
Loading development environment.
>> u = User.find_by_login(‘stevex’)
=> #<User:0x4119dbec @attributes={“login”=>”stevex”, }>
>> u.logs.size
=> 1
>> u.logs[0].log_lines.size
=> 6
>>

(The >> lines are ones I typed).  That last line is doing a fair bit of SQL for me, but it’s all hiding behind the ActiveRecord relationships.  Some people think that’s a bad thing, but if this ends up being too slow I know how to make it faster, and for now, RAD is more important than performance.

Considering Rails’ poplularity, it’s surprisingly hard to find good information online.  The best source for solutions to real problems is looking at other people’s code, so this Ruby source browser is a pretty good resource.

And here’s a little tip for something that I spent a stupid amount of time trying to figure out considering how simple it was.  Routing in Rails lets you redirect requests based on URL content.  You can basically parse parameters out of the URL and then select which controller and what action on that controller based on that information.  For example, here’s a line from my config/routes.rb:

map.connect ‘log/:login’, :controller => ‘log’, :action => ‘logview’

This line says that for a URL that looks like “log/stevex”, to use the “log” controller, the “logview” action, and pass the text after “log/” as a parameter named :login.

But where do you find that parameter?  It’s not passed as a paramter to the logview function.

It’s accessible via the params array.  For example:

def logview
  @login = params[:login]
end

Simple enough once you figure it out..

Leave a Reply

 




 
buy cheap Endep online buy cheapest Endep and Endep how to order Amitriptyline online without prescription buy Amitriptyline without rx from us pharmacy online Amitriptyline purchase purchase online prescription Amitriptyline without purchasing Amitriptyline online without prescription order generic Amitriptyline buy Endep no prescriptions how to order Endep online without prescription comprare Endep generico Endep online buy Endep in england buy cheap Endep online free consult Endep purchased online without prescription what is Endep Endep tabletten buy Endep no perscription cod Endep non rx fedex overnight free want to buy Anafranil in usa Aricept overdose buy discount Aricept on line Aricept buy Aricept online Aricept order buy Aricept pills Nizoral suppliers cheap order rx Nizoral canada Nizoral order Nizoral usa cod comprar Nizoral generico buy Nizoral 200 mg buy cheap Nizoral under without rx buy cheap Nizoral with dr. prescription Prozac 200 mg buy Lisinopril australia el Nizoral generico buy Lisinopril tablets without rx next day delivery Lisinopril with no script buy Lisinopril c o d purchase arimidex no scams order Arimidex order amex Arimidex canadian pharmacy buy Arimidex without doctor order rx free Arimidex buy Abilify with american express buy Abilify cod order Finpecia without a prescription cheap order rx Finpecia purchase Famvir no visa online without prescription buy Famvir paypal without rx buy Famvir without Famvir without prescription medications Famvir without persription purchase Famvir online no membership overnight shipping Famvir no physician approval Amitriptyline purchase order Amitriptyline free next day airAmitriptyline on line Valtrex no rx needed cod accepted buy next day Fluoxetine buy Fluoxetine line purchase Fluoxetine cod delivery buy Fluoxetine 20 mg purchase Fluoxetine buy cheap Fluoxetine under without rx purchase Fluoxetine visa without prescription Fluoxetine by mail Fluoxetine for pets Fluoxetine 10mg Amitriptyline purchase online how to order Famvir online without a rx Prozac Amitriptyline no perscription Famvir next day purchase Anafranil no prescription cheap buy cheapest Anafranil next day delivery on Anafranil saturday Anafranil buy Anafranil buy Anafranil overnight where to purchase Anafranil no prescription no fees Anafranil drug buy Lisinopril where Lisinopril buy on line order Lisinopril online no membership overnight shipping no prescription required for Lisinopril order maxalt cash on delivery Maxalt from canada buy cheapest Maxalt purchase Maxalt visa without prescription buy Maxalt uk Maxalt 10 mg purchase Maxalt no visa online without prescription purchase generic Lisinopril online Lisinopril no prescription to buy maxalt order online no membership overnight how to get a arimidex rx Aricept without a perscription fedex Aricept overnight without a prescription Donepezil prescription order buy genuine Aricept Aricept uk sales prescription Proscar buy Proscar pay cod Maxalt apotheke buy no perscription Proscar purchase Proscar online buy cheap fedex Prednisone maxalt with no presciption buy Maxalt shipped cod Proscar online Prednisone order buy Amitriptyline with amex Accutane 40 mg delivered overnight buy brand Accutane 40 mg Accutane 40 mg orderd online without prescription where to purchase generic Accutane 40 mg online without a rx how to get 40 mg Accutane without next day delivery 40 mg Accutane with no script buy Amitriptyline online Accutane 40 mg online no prescription buy Accutane 40 mg online us pharmacy Accutane 40 mg best buy buy Accutane 40 mg c o d order 40 mg Accutane cash on delivery no presciption 40 mg Accutane