Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Init attributes and set value

Reply
Thread Tools

Init attributes and set value

 
 
Stephan Meier
Guest
Posts: n/a
 
      10-26-2008
Hey all,

sorry for the noob question.

But how can i init a big amount of attributes with empty strings.
And overwrite the empty string if the field of the form is filled with
some value.

I try update_attributes(hash) with no success.

Thanks for your help!
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
 
Robert Klemme
Guest
Posts: n/a
 
      10-26-2008
On 26.10.2008 16:54, Stephan Meier wrote:

> But how can i init a big amount of attributes with empty strings.


I'd use nil as the marker for uninitialized. This happens to be the
default and saves the overhead of all the empty strings. You can deal
with those nils later, i.e. when changing or outputting them, e.g.

def modify_whatever(s)
(@whatever ||= "") << s
end

def print_whatever
print @whatever || ""
end

You can even automate this by writing your own attr_accessor method that
will define getters like

def foo
@foo || ""
end

> And overwrite the empty string if the field of the form is filled with
> some value.


Form, what form?

> I try update_attributes(hash) with no success.


Can you be more specific about what you are really trying to do? Is
this web, UI or what?

Kind regards

robert
 
Reply With Quote
 
 
 
 
Stephan Meier
Guest
Posts: n/a
 
      10-26-2008
Hey,

thanks for your answer.

I have a form (html rails form) and want to generate a search url with
every textfield.

The URL looks like http://example.com?value1=&value2=&value3=& ....

The url has about 20 values but its not necessary every value has to be
filled.
So i want to update only these values from my "search form" wich have a
value and the rest with an empty string.

thanks for your help
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
Michael Guterl
Guest
Posts: n/a
 
      10-26-2008
On Sun, Oct 26, 2008 at 12:16 PM, Stephan Meier <(E-Mail Removed)> wrote:
> Hey,
>
> thanks for your answer.
>
> I have a form (html rails form) and want to generate a search url with
> every textfield.
>
> The URL looks like http://example.com?value1=&value2=&value3=& ....
>
> The url has about 20 values but its not necessary every value has to be
> filled.
> So i want to update only these values from my "search form" wich have a
> value and the rest with an empty string.
>
> thanks for your help


I'm sure Robert helped answer your question and I know this isn't the
Rails list, but this will hopefully help even further.

http://railscasts.com/episodes/111

HTH,
Michael Guterl

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
FF/Latch <idex_signimm_8> (without init value) has a constant value of 0 in block Spacebottle VHDL 1 05-24-2011 11:33 AM
init of class members : mem(0) vs. mem() vs. not-init at all news.aon.at C++ 11 01-29-2011 07:30 PM
questions about object initialization, default-init and value-init Jess C++ 4 05-04-2007 02:47 AM
Sequence Order between Page Init and User Control Init Tony Cheng ASP .Net 1 02-24-2006 01:56 PM
Compiler/Linker Error undefined reference to 'std::ios_base::Init::Init[in-charge]() clusardi2k@aol.com C++ 1 08-18-2005 07:11 PM



Advertisments