Hi there,

I was trying to be a little creative and play around with ruby. In my
RoR model file I wrote this:

Hash['title', 'teaser'].each do |k ,v|
validates v.to_sym :presence => true
end

It's fairly obvious what I'm trying to achieve here, but the validation
is only set for the last element, 'teaser'. I know there is something
about ruby block only returning the last line (or something), but is
there a way to circumvent that?

Regards,

Nadeem

--
Posted via http://www.ruby-forum.com/.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Search Discussions

  • Jim Ruther Nill at Dec 6, 2011 at 1:36 pm

    On Tue, Dec 6, 2011 at 9:25 PM, Nadeem Qureshi wrote:

    Hi there,

    I was trying to be a little creative and play around with ruby. In my
    RoR model file I wrote this:

    Hash['title', 'teaser'].each do |k ,v|
    validates v.to_sym :presence => true
    end
    Hash['title', 'teaser'] creates a hash with one pair. Inside the block,
    k is assigned 'title' and v is assigned 'teaser'. try

    ['title', 'teaser'].each do |k|
    validates k.to_sym, :presence => true
    end

    It's fairly obvious what I'm trying to achieve here, but the validation
    is only set for the last element, 'teaser'. I know there is something
    about ruby block only returning the last line (or something), but is
    there a way to circumvent that?

    Regards,

    Nadeem

    --
    Posted via http://www.ruby-forum.com/.

    --
    You received this message because you are subscribed to the Google Groups
    "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to
    rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at
    http://groups.google.com/group/rubyonrails-talk?hl=en.

    --
    -------------------------------------------------------------
    visit my blog at http://jimlabs.heroku.com

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouprubyonrails-talk @
categoriesrubyonrails
postedDec 6, '11 at 1:26p
activeDec 6, '11 at 1:36p
posts2
users2
websiterubyonrails.org
irc#RubyOnRails

2 users in discussion

Nadeem Qureshi: 1 post Jim Ruther Nill: 1 post

People

Translate

site design / logo © 2021 Grokbase