In a class called 'Quality' I have the following constants defined:
class Quality < ActiveRecord::Base
[validations excluded in this example]
NEW = Quality.find_by_name("New")
LGT = Quality.find_by_name("Light use")
MED = Quality.find_by_name("Medium use")
HVY = Quality.find_by_name("Heavy use")
SCR = Quality.find_by_name(...
Hi, I get the following error:
undefined method `[]' for nil:NilClass
The related snippet in line 50:
47: <%=h @contact.date_entered.to_date %></br>
48: Next event:
49: <% next_delayed_todo = @contact.next_delayed_todo %>
50: <% unless next_delayed_todo[:event].nil? %>
52: <%= next_delayed_todo[:event].title %> </br>
...
I am currently using the following:
20: <p>Status: <%= @contact.try(:status) unless @contact.nil? || @contac
t.status.nil?%></p>
However, I still get the following error:
ActionView::TemplateError (undefined method `status' for nil:NilClass) on line #
20 of app/views/contacts/show.html.erb:
Is there a better way to be check...
Does anyone know in which situations initializing a NSURLConnection returns nil instead of the created connection. The documentation says it's possible but fails to specify when this happens.
The method/message in question:
[[NSURLConnection alloc] initWithRequest:request delegate:self];
-
According to the NSURLConnection Class Refer...
Hi,
sthis is very annoying, since now my values are stored as if they contain somethin by default (like in c). All my OO stuff are now broken since my delegate are always somethin. I was wonderin why XCode do this to me, since by default XCode always set the variable value to 0 or nil.
So if i do
NSArray* anArray;
and then
NSLog(%@"...
I am not experienced in Ruby, so my code feels "ugly" and not idiomatic:
def logged_in?
!user.nil?
end
I'd rather have something like
def
user.not_nil?
end
But cannot find such a method that opposites nil?
...
I have a custom CALayer (say CircleLayer), containing custom properties (radius and tint). The layer renders itself in its drawInContext: method.
- (void)drawInContext:(CGContextRef)ctx {
NSLog(@"Drawing layer, tint is %@, radius is %@", self.tint, self.radius);
CGPoint centerPoint = CGPointMake(CGRectGetWidth(self.bounds)/2, C...
Those stupid 'string'.method! returning nil instead of self in ruby - can be easily overriden:
class String
['strip!', 'upcase!', 'downcase!', 'capitalize!', 'chop!', 'chomp!', 'delete!', 'gsub!'].each do |meth|
orig_meth = "orig_#{meth}"
alias_method orig_meth, meth
define_method(meth) do |*args|
...