Testing and assigning with regexp's

I’m new to Ruby, and in a little program I’m writing, I have code like
this:

str = ‘’
if /something/.match(str)
str = /something/.match(str)[1]
end

Is there a more elegant way to do this?

Mike S.

str = $& if str =~ /something/

Although, running this when str == ‘’ is pretty useless.

Mike S. wrote:

Mike S.

str = ‘’
m = /something/.match(str)
str = m[1] if m

On Wed, May 02, 2007 at 08:23:13PM +0900, Tim H. wrote:

Mike S.

str = ‘’
m = /something/.match(str)
str = m[1] if m

A useful pattern is:
str = $1 if /(something)/ =~ str

or without the capture:
str = $& if /something/ =~ str

Hi,
I’m trying to pass an object from the View to the controller as a
hidden field.

Two quick questions:
For a hidden field, how do I pass a complete object to the controller?
For example, I have an object of type Issue, what should the second
argument be in the
following:

<%= hidden_field(“issue”, ?, “value” => @issue) %>

Secondly, how would I access this object in the controller?

Any help would be appreciated.

Thanks,
Anupam.

Agnisys wrote:

Secondly, how would I access this object in the controller?

Any help would be appreciated.

Firstly:

Please don’t start a new topic by hitting “Reply” in your mail
application. This messes with the threaded view used by a significant
number of users, and you might not get answers.

Secondly:
The Rails groups can help you more with this question, I guess:


Phillip “CynicalRyan” Gawlowski
http://cynicalryan.110mb.com/
http://clothred.rubyforge.org

Rule of Open-Source Programming #5:

A project is never finished.

On Wed, 02 May 2007 23:42:09 +0900, Phillip G. wrote:

Secondly:
The Rails groups can help you more with this question, I guess:
Ruby on Rails — Community

But what about people, who do not want to use ugly webforums or
even-more-ugly mailing lists which flood their mailboxes?

Do you know about a newsgroup where one can discuss rails topics?

Regards
Thomas

zaphod wrote:

On Wed, 02 May 2007 23:42:09 +0900, Phillip G. wrote:

Secondly:
The Rails groups can help you more with this question, I guess:
Ruby on Rails — Community

But what about people, who do not want to use ugly webforums or
even-more-ugly mailing lists which flood their mailboxes?

What do you think is this? If you don’t want to use the sources of
information that are available to you, you are out of luck, harsh as it
may sound.

Do you know about a newsgroup where one can discuss rails topics?

Very first entry on this website:


Phillip “CynicalRyan” Gawlowski
http://cynicalryan.110mb.com/
http://clothred.rubyforge.org

Rule of Open-Source Programming #15:

If you like it, let the author know. If you hate it, let the author
know why.

On Wed, 02 May 2007 21:03:00 +0900, Agnisys wrote:

I really do not understand, what you want to do. Which sense does it
make,
to pass an entire object into a form and back to the controller,
when you do not want to manipulate it in the form? You could store it in
the session instead or fetch it from the database, when it lives there
after you got the form posted back.

From your posting one can assume, that you do not know nothing about
rails
at all, then I would recommend to search http://www.rubyonrails.org/ for
a
tutorial and http://api.rubyonrails.org/ for the APIs documentation or
read a book like “Agile Web D. with Rails” from Dave
Thomas and David Heinemeier H…

If you want more help here, please describe your problem more detailed.

Regards
Thomas

At the bottom of the Google G. Page it give you the address for
sending
mail to the group:

[email protected]

If you just want to search then just search. You don’t have to have a
google account, although it isn’t hard to get one.

On 5/2/07, zaphod [email protected] wrote:

But what about people, who do not want to use ugly webforums or
Ruby on Rails — Community

The very first entry “general list” is not a news group but a google
group, for which I need a google account - or am I wrong and there is a
way to use them in my newsreader via nntp?

Ragards
Thomas


“Hey brother christian with your high and mighty errand, Your actions
speak
so loud, I can’t hear a word you’re saying.”

-Greg Graffin (Bad Religion)

You will need to pass the id and then get the object from the db using
the
id in the controller.

Secondly - ruby is the language in which rails is developed. This list
is
for the language, which is used for more than just rails, so posting
rails
questions to this list is annoying to people who have nothing to do with
rails.

For rails related questions join the rails mailing list:

Regards
Ivor

On Thu, 03 May 2007 00:09:46 +0900, Phillip G. wrote:

What do you think is this?
A news group about “ruby”? As far as I understood your last posting,
comp.lang.ruby is not for discussing rails topics.

Do you know about a newsgroup where one can discuss rails topics?

Very first entry on this website:
Ruby on Rails — Community

The very first entry “general list” is not a news group but a google
group, for which I need a google account - or am I wrong and there is a
way to use them in my newsreader via nntp?

Ragards
Thomas

On Thu, 03 May 2007 00:40:15 +0900, Phillip G. wrote:

zaphod wrote:

A news group about “ruby”? As far as I understood your last posting,
comp.lang.ruby is not for discussing rails topics.

On my end, it’s a mailing list. For others, it is a webforum…

And on my end it is a usenet newsgroup. But as far as I know, even
google
makes a difference between usenet and mailinglists or google groups
though
they have built various gateways into usenet. And usenet people
definitly
do.

In general, you want to ask Rails questions in the Rails mailinglist, as
your chances of getting an answer are higher by an order of magnitude.

Yes. But I am searching for a usenet newsgroup for rails because without
a
comfortable newsreader I would not read it anyway. But you are probably
the wrong person to ask.

The very first entry “general list” is not a news group but a google
group, for which I need a google account - or am I wrong and there is a
way to use them in my newsreader via nntp?

I have no clue. I use the email feature Google G. provides. You’d be
better of to seek for that answer in the Google G. support.

Again: I am not using google at all. But to get a clue, what I am
talking
about: Usenet - Wikipedia

Regards
Thomas

zaphod wrote:

A news group about “ruby”? As far as I understood your last posting,
comp.lang.ruby is not for discussing rails topics.

On my end, it’s a mailing list. For others, it is a webforum…

In general, you want to ask Rails questions in the Rails mailinglist, as
your chances of getting an answer are higher by an order of magnitude.

The very first entry “general list” is not a news group but a google
group, for which I need a google account - or am I wrong and there is a
way to use them in my newsreader via nntp?

I have no clue. I use the email feature Google G. provides. You’d be
better of to seek for that answer in the Google G. support.


Phillip “CynicalRyan” Gawlowski
http://cynicalryan.110mb.com/
http://clothred.rubyforge.org

Rule of Open-Source Programming #8:

Open-Source is not a panacea.

Tim H. [email protected] writes:

Mike S.

str = ‘’
m = /something/.match(str)
str = m[1] if m

str = str[/something/, 1] || str

Thanks Igor for you useful response. I would try the Rails community.
I didn’t realize this is a Ruby ONLY list.

Anupam.

On 5/4/07, Christian N. [email protected] wrote:

end

Is there a more elegant way to do this?

Mike S.

str = ‘’
m = /something/.match(str)
str = m[1] if m

str = str[/something/, 1] || str

In that vein,
str.gsub!(/\A.(something).\z/, ‘\1’)