Senior & Expert RoR Developers Discussion Forum by Nyros Technologies

HIRE Ruby on Rails Expert Developers Programmers Coders From India
Ruby on Rails PHP .Net Developers Community, Nyros Technologies, Kakinada
 
Log in  or IF not a member please REGISTER
Username:
Password:   


Keyword
Log in | Profile 

How to check whether the rado button selected or not from mo

 
Post new topic   Reply to topic    Senior & Expert RoR Developers Discussion Forum by Nyros Technologies Index -> Advanced programming
View previous topic :: View next topic  
Author Message
raviprakash



Joined: 21 Aug 2007
Posts: 29

PostPosted: Wed Jul 01, 2009 6:24 am    Post subject: How to check whether the rado button selected or not from mo Reply with quote

Hi,

I am trying to do validates_presence_of on a value only if the corresponding radio button is checked. I can access radio button values in the controller with params but it doesn't seem to work in the model.

Thanks in advance
Back to top
View user's profile Send private message
s.nagesh



Joined: 23 Jul 2007
Posts: 115

PostPosted: Wed Jul 01, 2009 6:44 am    Post subject: Reply with quote

class YourModel < ActiveRecord::Base
validates_presence_of :value, :if => Proc.new {|p| p.radio_button_for_value}
attr_accessor :radio_button_for_value
end

The Proc here is bound to the object you're validating. So, the 'p' in this code is your object. In this case, if p.radio_button_for_value is nil or false, the validation will be skipped. If the rest of your validations pass, your object will return valid.

If you're looking for a specific value, use the follwing code.

class YourModel < ActiveRecord::Base
validates_presence_of :value, :if => Proc.new {|p| p.radio_button_for_value == value_to_skip_validation}
attr_accessor :radio_button_for_value
end
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Senior & Expert RoR Developers Discussion Forum by Nyros Technologies Index -> Advanced programming
Page 1 of 1

 latest topics 
 Topics   Replies   Author   Views   Last Post 
No new posts User defined classes and types of variables.
2 swaminadhan 25 Wed Mar 10, 2010 4:40 am
swaminadhan View latest post
No new posts Background & Introduction of ruby
0 Divya 30 Mon Mar 08, 2010 12:59 pm
Divya View latest post
No new posts i have lost the data in schema.rb file in rails application
0 Raja 38 Thu Mar 04, 2010 4:46 am
Raja View latest post
No new posts AlertPay
0 Raghu 27 Mon Mar 01, 2010 11:36 am
Raghu View latest post
No new posts have a problem while working with facebooker plugin
1 krishnakanth 30 Mon Mar 01, 2010 9:31 am
sharma I View latest post
No new posts Having issues while trying to run the application
1 sharma I 31 Mon Mar 01, 2010 8:56 am
swaminadhan View latest post
No new posts getting twitter tweets using twitter gem
0 sharma I 23 Mon Mar 01, 2010 8:21 am
sharma I View latest post
No new posts JavaScript functionality with Event handling class
0 umamahesh_nyros 22 Mon Mar 01, 2010 7:25 am
umamahesh_nyros View latest post
No new posts Differences between form_for and form_tag in rails
0 sharma I 36 Mon Mar 01, 2010 7:19 am
sharma I View latest post
No new posts uninitialized constant HomeController::Money
1 Akshay 40 Mon Mar 01, 2010 6:27 am
sharma I View latest post




Hire an expert Ruby on Rails developer / coder / programmer or development team from India now!!

Other Forums : PHP   ::   .Net   |   Free unlimited HTML CSS templates download

Nyros Technologies   |   Kakinada City Portal   |   Developers Blog   |   About Ruby on Rails Experts   |   More