11175
(-- --)
April 3, 2008, 9:15am
1
Is it possible somehow to incorporate "this is a text" into a
"blob/text"-value in the database when the row is created?
It's not possible to do with a default value hence it's a
"blob/text"-value.
At the moment I create the row for a user with:
@presentation = current_user.presentation
@presentation = current_user.create_presentation unless @presentation
11175
(-- --)
April 3, 2008, 12:40pm
2
I tried to create this in my lib file string.rb to show something else
if the value was nil...(and required the 'string.rb' in my application
helper)
def or_empty(alternate)
(self.nil? or self == "") ? alternate : self
end
but that didn't work either.
You'd need to open the class up to do this.
class String
def or_empty(alternate = 'default')
self.blank? ? alternate : self
end
That would work.
Julian.
Learn Ruby on Rails! CHECK OUT THE FREE VIDS (LIMITED TIME) VIDEO #3
OUT APRIL 6
http://sensei.zenunit.com/
11175
(-- --)
April 4, 2008, 9:08am
4
Julian Leviston wrote:
You'd need to open the class up to do this.
class String
def or_empty(alternate = 'default')
self.blank? ? alternate : self
end
That would work.
Julian.
Learn Ruby on Rails! CHECK OUT THE FREE VIDS (LIMITED TIME) VIDEO #3
OUT APRIL 6
http://sensei.zenunit.com/
Nope, that doesn't do it,
I still get an error
"The error occurred while evaluating nil.or_empty"
in this line of my show-view:
<%= h @presentation.pres.or_empty ("No presentation has been entered")%>
because the there exists nothing in the pres-field. This is what I'm
trying to fix.
what do you mean with:
How about you do this in your model
def pres
value_in_database = self[:pres]
#do something with value_in_database
end
Fred
Frederick Cheung wrote:
because the there exists nothing in the pres-field. This is what I'm
trying to fix.
How about you do this in your model
def pres
value_in_database = self[:pres]
#do something with value_in_database
end
Fred
I'm not quite sure I completely understand... =/
Overwrite the accessor that rails provides, using self[:pres] to get
at the original value.
Fred