Recently while coding in rails, i had a column called in one of the tables
and hence was wrapped up by ActiveRecord.
Guess, what it broke entire of the code, because quote is a already defined
method somewhere in rails. I had trouble in finding out the root of the
problem.
Another example, as a newbie to ruby and rails I was using login_engine in
my rails code. I have a table called messages in my database. Now,
login_engine controller code is like this:
User.transaction(@user) do @user.new_password = true
unless LoginEngine.config(:use_email_notification) and
LoginEngine.config(:confirm_account) @user.verified = 1
end
if @user.save
key = @user.generate_security_token
url = url_for(:action => 'home', :user_id => @user.id, :key =>
key)
flash[:notice] = 'Signup successful!'
if LoginEngine.config(:use_email_notification) and
LoginEngine.config(:confirm_account)
UserNotify.deliver_signup(@user, params[:user][:password], url)
flash[:notice] << ' Please check your registered email account
to verify your account registration and continue with the login.'
else
flash[:notice] << ' Please log in.'
end
redirect_to :action => 'login'
end
end
Guess, what User.transaction was behaving oddly because it was throwing
warning "Messages already defined constant". The error was shown in web
server logs and hence again was a little difficult to track.
Now, how as a new guy to ruby and rails, how do i know , i shouldn't have a
column called quote and i shouldn't have a table called messages.
I am a Qt/C++ programmer also, and the namespace issue is mostly
non-existent there.First of all, its because all the Qt classes begin with Q
and hence you know.But Ruby library authors seems a little lax on this, and
open classes make the entire thing a little nifty and difficult to debug if
you are caught on the wrong foot.Either library authors should avoid
writting classes like Messages or ruby should give option of importing only
certain methods from a module.
Something like:
using std::cout;
But still i am new to ruby(3 months precisely), so if you wish you can take
my assertions with a grain of salt.
Recently while coding in rails, i had a column called in one of the tables
and hence was wrapped up by ActiveRecord.
Guess, what it broke entire of the code, because quote is a already defined
method somewhere in rails. I had trouble in finding out the root of the
problem.
Another example, as a newbie to ruby and rails I was using login_engine in
my rails code. I have a table called messages in my database. Now,
login_engine controller code is like this:
[snip code]
Guess, what User.transaction was behaving oddly because it was throwing
warning "Messages already defined constant". The error was shown in web
server logs and hence again was a little difficult to track.
Now, how as a new guy to ruby and rails, how do i know , i shouldn't have a
column called quote and i shouldn't have a table called messages.
I am a Qt/C++ programmer also, and the namespace issue is mostly
non-existent there.First of all, its because all the Qt classes begin with Q
and hence you know.But Ruby library authors seems a little lax on this, and
open classes make the entire thing a little nifty and difficult to debug if
you are caught on the wrong foot.Either library authors should avoid
writting classes like Messages or ruby should give option of importing only
certain methods from a module.
Something like:
using std::cout;
But still i am new to ruby(3 months precisely), so if you wish you can take
my assertions with a grain of salt.
This is in some ways more of a Rails problem than ruby problem and involves the way rails works, with you inheriting from Rails' classes. That particular problem would actually not be solved by C++ style namespaces or even Q-prefixes. A potential solution to the problems you've experienced are the idea of selector namespaces which have been tossed around on the ML before.
Why not, if rails would have been coded to have proper prefixes in the
classes/modules, I would have avoided that trouble?
···
On 9/1/06, Logan Capaldo <logancapaldo@gmail.com> wrote:
On Aug 31, 2006, at 9:03 PM, Hemant . wrote:
> Recently while coding in rails, i had a column called in one of the
> tables
> and hence was wrapped up by ActiveRecord.
> Guess, what it broke entire of the code, because quote is a already
> defined
> method somewhere in rails. I had trouble in finding out the root of
> the
> problem.
>
> Another example, as a newbie to ruby and rails I was using
> login_engine in
> my rails code. I have a table called messages in my database. Now,
> login_engine controller code is like this:
>
[snip code]
> Guess, what User.transaction was behaving oddly because it was
> throwing
> warning "Messages already defined constant". The error was shown in
> web
> server logs and hence again was a little difficult to track.
>
> Now, how as a new guy to ruby and rails, how do i know , i
> shouldn't have a
> column called quote and i shouldn't have a table called messages.
>
> I am a Qt/C++ programmer also, and the namespace issue is mostly
> non-existent there.First of all, its because all the Qt classes
> begin with Q
> and hence you know.But Ruby library authors seems a little lax on
> this, and
> open classes make the entire thing a little nifty and difficult to
> debug if
> you are caught on the wrong foot.Either library authors should avoid
> writting classes like Messages or ruby should give option of
> importing only
> certain methods from a module.
> Something like:
>
> using std::cout;
>
> But still i am new to ruby(3 months precisely), so if you wish you
> can take
> my assertions with a grain of salt.
This is in some ways more of a Rails problem than ruby problem and
involves the way rails works, with you inheriting from Rails'
classes. That particular problem would actually not be solved by C++
style namespaces or even Q-prefixes. A potential solution to the
problems you've experienced are the idea of selector namespaces which
have been tossed around on the ML before.
class RailsPrefixActiveRecord
def hello
... does something useful ...
end
end
class YourClass < RailsPrefixActiveRecord
belongs_to :hello
end
Do you see the issue now? Prefixes still wouldn't have helped your problem, unless you wanted to prefix every method call, which is I think we can agree ridiculous.
(P.S.: Please don't top-post)
···
On Aug 31, 2006, at 9:41 PM, Hemant . wrote:
Why not, if rails would have been coded to have proper prefixes in the
classes/modules, I would have avoided that trouble?
On 9/1/06, Logan Capaldo <logancapaldo@gmail.com> wrote:
On Aug 31, 2006, at 9:41 PM, Hemant . wrote:
> Why not, if rails would have been coded to have proper prefixes in the
> classes/modules, I would have avoided that trouble?
>
class RailsPrefixActiveRecord
def hello
... does something useful ...
end
end
class YourClass < RailsPrefixActiveRecord
belongs_to :hello
end
Do you see the issue now? Prefixes still wouldn't have helped your
problem, unless you wanted to prefix every method call, which is I
think we can agree ridiculous.
Why not, if rails would have been coded to have proper prefixes in the
classes/modules, I would have avoided that trouble?
class RailsPrefixActiveRecord
def hello
... does something useful ...
end
end
class YourClass < RailsPrefixActiveRecord
belongs_to :hello
end
Do you see the issue now?
<raise hand> Um, I don't. Since he said "prefixes IN the classes/modules" and not "prefixes OF the classes/modules", I would expect something like
class RRActiveRecord
def rrhello
... does something useful ...
end
end
Yes? No? On the other hand, I have no idea what "belongs_to" does, so maybe that's why this doesn't make any sense to me...
Prefixes still wouldn't have helped your problem, unless you wanted to prefix every method call, which is I think we can agree ridiculous.
Hmm. I've somehow not found that ridiculous in the case of Macintosh OSX/Cocoa et al., where just about every imaginable object begins with NS (for NextStep, as it happens). I collect NSEvents from my NSWindow with its NSView with an NSTextField that gives me an NSString. That's really worked pretty well for me so far.
I said prefix every method. Every Cocoa/NextSTEP method is not prefixed with NS. You don't say [@"one.two.three" NScomponentsSeparatedByString:@"."] you say [@"one.two.three" componentsSeparatedByString: @"."]. Maybe I over-generalized when I said we could agree that it was ridicolous, but NextSTEP / Cocoa is not an example of prefixing every method call.
···
On Sep 5, 2006, at 7:32 PM, Dave Howell wrote:
Prefixes still wouldn't have helped your problem, unless you wanted to prefix every method call, which is I think we can agree ridiculous.
Hmm. I've somehow not found that ridiculous in the case of Macintosh OSX/Cocoa et al., where just about every imaginable object begins with NS (for NextStep, as it happens). I collect NSEvents from my NSWindow with its NSView with an NSTextField that gives me an NSString. That's really worked pretty well for me so far.