[Rails] Re: What is the Ruby idiom for this?
Yes, ORMs are wonderful, once you learn the abstraction layer. But --
and I know some will take offense at this -- there are things to avoid
in learning Ruby, and just use the old tried-n-true (many things, like
using straight Javascript for most of the Ajax-like things you want to
do, or for db-query-b ased algorithms, like I am trying to accomplish
here, sticking with as straight of an sql interface as possible). This
is true of most languages, if you can learn a more generic means of
implementing the language, you are not only up-to-speed faster, BUT,
you generally have a finer-grained control over what you ware
implementing.
The algorithm I am looking to sweeten of:
# Is the associate in the list - if not, make it the person at
the top of the list.
@up = Up.find(params[:id]) #get the individual up record which
has the associate and channel
@associate = @up.associate #specify ref to the associate in question
#see if this associate is in the current list
@Qplayers = Qplayer.find_by_sql(["select * from qplayers where
associate_id=? and channel_id=? and
inlist=1",@associate.id,@associate.channel_id])
if @Qplayers[0].blank? #if the associate from the up in the row is in
the list, it wont be blank
@Qplayers = Up.find_by_sql(["select * from qplayers where
channel_id=? and inlist=1 order by battingorder ASC",@up.channel_id])
@Qplayer = @Qplayers[0]
@associate = @Qplayer.associate
end
I'm not sure can be more clearly expressed in a "sweeter" way,
especially if the criteria changes in the future -R.Vince
On Nov 22, 10:59 am, Eno <ra...@bitblit.net> wrote:
> On Sun, 22 Nov 2009, RVince wrote:
> > See, I don't htink there IS an easier way -- just a Ruby-occluded way
> > called .find_by_sql(["select ..."])
>
> > A lot of this syntactic sugar really gets in the way. Rails is great,
> > as a web framework -- far superior to something like Struts. But in
> > the end, it;s back to JRuby, writing the back end in the C-like
> > syntax of Java, and avoiding Ruby and it's idioms, making use of Rails
> > this way.
>
> I wasn't saying use Rails, just ActiveRecord. And DBI is fairly light and
> gives you database independance.
>
> You know what an ORM is right? That's really nice syntactic sugar.
>
> --
> A
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home