Forum: Ruby on Rails ActiveRecord's type_cast method?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Eea3feaacbe44706164289d068d94828?d=identicon&s=25 petermichaux (Guest)
on 2005-11-14 05:48
(Received via mailing list)
Hi,

I'm looking at the type_cast method in
activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb

I can see that the case statement is dependant on the variable "type"
which
looks like a local variable. But where is type set? Maybe this is more
of a
Ruby question.

Thanks,
Peter


def type_cast(value)
return nil if value.nil?
case type
when :string then value
when :text then value
when :integer then value.to_i rescue value ? 1 : 0
when :float then value.to_f
# ...more...
else value
end
end
24d2f8804e6bb4b7ea6bd11e0a586470?d=identicon&s=25 jeremy (Guest)
on 2005-11-14 06:00
(Received via mailing list)
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Nov 13, 2005, at 8:45 PM, Peter Michaux wrote:
> I can see that the case statement is dependant on the variable
> "type" which looks like a local variable. But where is type set?
> Maybe this is more of a Ruby question.

That's a call to the type method on Column.

jeremy
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (Darwin)

iD8DBQFDeBnLAQHALep9HFYRAhKnAJ4zTnXd20N3t1/yoBsKsfe2OpIuQQCfVMC3
QLqrql6YNs9tnYScaViguOc=
=34/i
-----END PGP SIGNATURE-----
132a94ca65959bda6c74fae54bff2425?d=identicon&s=25 ezra (Guest)
on 2005-11-14 06:09
(Received via mailing list)
Peter-

	type is a ruby method that returns the type or class of the object
like this:

a = "this is a string"
a.type #=> String

HTH
-Ezra

On Nov 13, 2005, at 8:45 PM, Peter Michaux wrote:

> Thanks,
>     # ...more...
>     else value
>   end
> end
> _______________________________________________
> Rails mailing list
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails

-Ezra Zygmuntowicz
WebMaster
Yakima Herald-Republic Newspaper
ezra@yakima-herald.com
509-577-7732
5565e460a42fbe5669b458b2753f8d34?d=identicon&s=25 codeslush (Guest)
on 2005-11-14 06:36
(Received via mailing list)
ROR community,


  I have been using Rails now for just two weeks. I am very happy with
what I have found and am overly impressed with the quality and
timeliness of feedback that this community provides. I wanted to take a
moment to explain briefly my background and how I ended up here. Perhaps
this will not be of personal interest to anyone, but it speaks volumes
about Rails.


  I have been professionally developing applications for over 10 years,
the last seven of which were done as an independent consultant.
Historically, I avoided unix, linux, and anything related like the
plague. Not because it was not good technology, but because I hid under
the Microsoft umbrella. Now I'm involved with a startup and licensing is
a major issue. It has forced me to step into this vast world of open
source software and allowed me to confront one of my biggest technical
fears and weaknesses Â? the LAMP stack.


  Desperately needing an open source CRM solution.  I first found
SugarCRM, then I stumbled upon vTiger. Both had their strengths and
their weaknesses. The major problem, though, was customization. I am not
a PHP programmer but the language seemed simple enough. However, with
both of the above packages, I found the code to be horribly difficult to
follow. I found single functions containing over 800 lines of code.
After a few weeks of bouncing back and forth between the two of them, I
finally realized I was dealing with something I didn't want to deal
with. I quit.


  I began a new search. Realizing that probably nothing open source was
going to be any better than what I had already found, I was willing to
build something custom. I figured I would start with bare bones
functionality and enhance as time permitted. I found ActiveGrid.
Something that looks quite promising, but little/no community to back
it. I downloaded it, played with it a bit and was pretty happy with what
I saw. I ran into a problem...no one was available to answer it. No
community. Just a few forums that are largely untouched on SourceForge.
Maybe in a year or two it will be where it needs to be Â? but for now it
was just too risky for me to justify.


  Ruby on Rails kept popping up in various places Â? forums, blogs,
etc... I had never heard of Ruby or Rails (remember my background).
Something caught my eye somewhere and led me down this path. The
community is so strong and that is very impressive to me. I feel very
ignorant to this new world Â? it is almost like starting over from
scratch. BizTalk, C#, ASP.NET, WebServices, XML, XSLT, VB, COM/DCOM,
SQL, etc... - no problem. I have been very isolated to the Microsoft
world. I must say that I find all the different terminology,
applications, mechanisms for updates, etc... in the open source
community to be very intimidating. But I LOVE Rails. In just a little
over a week of playing around with it, I have made significant progress
on building a custom CRM solution. To be sure, I have weeks ahead of me
to get a fully functional system. But I know what I need to do is
possible. The Proof of Concept is complete and it is very true that this
framework allows you to accomplish mor
 e with
 less code. If you have seen the vTiger interface then you will know
what my CRM solution will look like. I have plugged Rails into that look
and feel and am making great progress each day. I hope to one day
publish it as open source for others to benefit from as well.


  As a bonus, I have a fully functional Asterisk PBX (open source)
managing the phone system. Wow...how about that? Yes, I will tie it into
Ruby Â? or borrow someone else's code that has already done it.


  Thank you David for providing this framework. Thank you ROR community
for providing the kind of support that you provide to make people like
me willing to take a risk on something that isn't even at Release 1.0
yet!


  Respectfully,


  Michael
81194a50c0f9bd95d7832a77fdf371bd?d=identicon&s=25 cool_screen_name90001 (Guest)
on 2005-11-14 06:54
(Received via mailing list)
So you come from .Net/C#? How does Rails/Ruby compare?

csn
24d2f8804e6bb4b7ea6bd11e0a586470?d=identicon&s=25 jeremy (Guest)
on 2005-11-14 06:57
(Received via mailing list)
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Nov 13, 2005, at 9:34 PM, Michael wrote:
> Thank you David for providing this framework. Thank you ROR
> community for providing the kind of support that you provide to
> make people like me willing to take a risk on something that isn't
> even at Release 1.0 yet!

Welcome to Rails, Michael; it's great to have you on board!

jeremy

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (Darwin)

iD8DBQFDeCcJAQHALep9HFYRAj6NAJoDvJgu5K6dbCB6AFzW6gn+Z65s2gCfcmdv
g+EKnTb287R6HniPTDDF01Q=
=hSDU
-----END PGP SIGNATURE-----
5565e460a42fbe5669b458b2753f8d34?d=identicon&s=25 codeslush (Guest)
on 2005-11-14 07:15
(Received via mailing list)
csn,

  This is probably not a fair question for me to answer.  I primarily
built b2b apps and line of business apps with .NET using things like
remoting, webservices, etc...  I like C#.  It makes sense to me.  But it
makes sense because I worked with MS technologies exclusively for a
decade.  To be quite honest, I have had a little bit of a difficult time
picking up Ruby - not quite sure why.  I easily learned C#, JavaScript,
PHP seemed easy enough, and any other language has been pretty simple.
Ruby, though, has me a little stumped at times.  It is just different
enough from other languages that it forced me to buy a book to
understand the diffs between basic things like @, @@, single quote,
double quote statements, do, etc..!!  :-)  It is my own ignorance - not
the language itself.  Shame on me for thinking I could just look at a
few code samples and figure it out.

  As for rails, I have never had an easier time with data access.  The
framework of rails is extremely simple...in fact, I don't know if data
access could be any easier than rails makes it.  I have never worked
with the MVC design pattern before - so I don't know if it is rails or
the pattern - but I love the way the code flows and the way it is
separated into the appropriate areas.

  I like the structure that Rails provides up front.  It gives me a
great starting point from which I can quickly make changes and add
functionality.

  I worry about performance - but a worry that currently doesn't have
any merit from my perspective.  In looking through the log files, I see
a lot of SQL statements being generated - which may be okay - or maybe
not.  I'll worry about that later.  It's open source, so I can change
anything I don't like!

  I'm not quite sure the depth of info you are looking for, but I wrote
this post because I'm extremely impressed with the framework and the
community.  Rails will do what I need it to do - and that is the most
important thing.  More importantly - - - it will do it in a cost
effective manner, which is the key to me!  I believe this thing is going
to take off in a huge way and am happy that I found it when I did.  I
may be late to the table, but I know I'm still on the ground floor.
i.e. - many more will adopt this - just wait and see!  I know a good
thing when I see it - and this is definitely a good thing!

  Michael



CSN <cool_screen_name90001@yahoo.com> wrote:

So you come from .Net/C#? How does Rails/Ruby compare?

csn
81194a50c0f9bd95d7832a77fdf371bd?d=identicon&s=25 cool_screen_name90001 (Guest)
on 2005-11-14 07:41
(Received via mailing list)
> This is probably not a fair question for me to
answer.  I primarily built b2b
> apps and line of business apps with .NET using
things like remoting,
> webservices, etc...  I like C#.  It makes sense to
me.  But it makes sense
> because I worked with MS technologies exclusively
for a decade.  To be quite
> honest, I have had a little bit of a difficult time
picking up Ruby - not quite
> sure why.  I easily learned C#, _JavaScript, PHP
seemed easy enough, and any
> other language has been pretty simple.  Ruby,
though, has me a little stumped at
> times.  It is just different enough from other
languages that it forced me to
> buy a book to understand the diffs between basic
things like @, @@, single
> quote, double quote statements, do, etc..!!  :-)  It
is my own ignorance - not
> the language itself.  Shame on me for thinking I
could just look at a few code
> samples and figure it out.

I was just curious what Ruby/Rails offers/lacks
comparatively. C#/.Net seems pretty nice, but I don't
think I'd want to buy into MS. I played around with
Mono a while ago - I'd probably go with it instead
(not that I'm planning to).

Ruby looked kind of strange to me at first - methods
with ?'s, blocks with |'s, words like 'yield',
Perl-like vars like @_ that I hate, etc. But it's
becoming rapidly familiar to me (after about 1.5 weeks
now) - and I think I actually like it. This online
book seems to explain everything:

http://www.rubycentral.com/book/

csn




__________________________________
Start your day with Yahoo! - Make it your home page!
http://www.yahoo.com/r/hs
D895471fbc8b3b1233a250186d542af8?d=identicon&s=25 Alexey Verkhovsky (alexeyv)
on 2005-11-14 07:44
(Received via mailing list)
CSN wrote:
> So you come from .Net/C#? How does Rails/Ruby compare?
>
I just about started to write an opinion, when I looked at who is
asking. cool_screen_name9001@yahoo.com
Hmm... Good old Ruby vs. Python flame war, anyone?

.NET is GREAT for anyone who likes drawing web forms in a visual
designer and creating code with GUI wizards. I doubt you will find
adepts of this method on the Rails list. However, there are quite a few
in real life, so it certainly has its target audience. Let's leave it at
that.

Alex
81194a50c0f9bd95d7832a77fdf371bd?d=identicon&s=25 cool_screen_name90001 (Guest)
on 2005-11-14 07:47
(Received via mailing list)
Huh? I'm not trying to start a flame war. Was an
honest question (and still is) - I don't know.

csn


--- Alexey Verkhovsky <alex@verk.info> wrote:

> in a visual
> _______________________________________________
> Rails mailing list
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>





__________________________________
Yahoo! Mail - PC Magazine Editors' Choice 2005
http://mail.yahoo.com
D895471fbc8b3b1233a250186d542af8?d=identicon&s=25 Alexey Verkhovsky (alexeyv)
on 2005-11-14 07:56
(Received via mailing list)
CSN wrote:
> Huh? I'm not trying to start a flame war. Was an
> honest question (and still is) - I don't know.
>
Hope so. It does look like an opening round of a classic flame war, when
you ask a highly controversial question using an anonymous nick. It's a
big downside of anonymous nicks.

Alex
5565e460a42fbe5669b458b2753f8d34?d=identicon&s=25 codeslush (Guest)
on 2005-11-14 08:05
(Received via mailing list)
Hhhhmmm.... Darn...I paid 45 bucks for the printed version!  But, I did
get version 2!  It's good too!  :-)

  Michael


CSN <cool_screen_name90001@yahoo.com> wrote:
  > This is probably not a fair question for me to
answer. I primarily built b2b
> apps and line of business apps with .NET using
things like remoting,
> webservices, etc... I like C#. It makes sense to
me. But it makes sense
> because I worked with MS technologies exclusively
for a decade. To be quite
> honest, I have had a little bit of a difficult time
picking up Ruby - not quite
> sure why. I easily learned C#, _JavaScript, PHP
seemed easy enough, and any
> other language has been pretty simple. Ruby,
though, has me a little stumped at
> times. It is just different enough from other
languages that it forced me to
> buy a book to understand the diffs between basic
things like @, @@, single
> quote, double quote statements, do, etc..!! :-) It
is my own ignorance - not
> the language itself. Shame on me for thinking I
could just look at a few code
> samples and figure it out.

I was just curious what Ruby/Rails offers/lacks
comparatively. C#/.Net seems pretty nice, but I don't
think I'd want to buy into MS. I played around with
Mono a while ago - I'd probably go with it instead
(not that I'm planning to).

Ruby looked kind of strange to me at first - methods
with ?'s, blocks with |'s, words like 'yield',
Perl-like vars like @_ that I hate, etc. But it's
becoming rapidly familiar to me (after about 1.5 weeks
now) - and I think I actually like it. This online
book seems to explain everything:

http://www.rubycentral.com/book/

csn




__________________________________
Start your day with Yahoo! - Make it your home page!
http://www.yahoo.com/r/hs
82476266af9d460415d8f1fc16bb54ed?d=identicon&s=25 jarkko (Guest)
on 2005-11-14 08:47
(Received via mailing list)
On 14.11.2005, at 9.05, Michael wrote:

> Hhhhmmm.... Darn...I paid 45 bucks for the printed version!  But, I
> did get version 2!  It's good too!  :-)

Don't be sorry. Ruby has evolved leaps since the version 1.0 and if
you plan to do any serious development on it, you want to have the
second edition. Plus, you're supporting a good cause. Now, if you
already didn't, go buy the Rails book, too :-)

//jarkko
E47445b68a7773fc134987c4ed3fd6d9?d=identicon&s=25 soulhuntre (Guest)
on 2005-11-15 09:58
(Received via mailing list)
Heya :)

> you will find adepts of this method on the Rails list.
> However, there are quite a few in real life, so it certainly
> has its target audience. Let's leave it at that.]

Of course .NET also happens to be a great, fast and powerful environment
that supports a variety of languages and development technologies. It
can be
used for far, far more than web forms as well.

While I am all for not having a Ruby vs. .NET flame war (especially as
the
conclusion on this list of foregone) but we could at least try to be a
little bit more accurate :)

Soulhuntre
----------

http://www.girl2.com  - my girls
http://www.the-estate.com  - my legacy
http://wiki.thegreybook.com - my project
http://weblog.soulhuntre.com - my thoughts
This topic is locked and can not be replied to.