# Calling model methods even when the param is a not set

**URL:** <https://www.ruby-forum.com/t/calling-model-methods-even-when-the-param-is-a-not-set/129488>\
**Category:** Rails\
**Created:** [February 19, 2008, 12:52am UTC](https://www.ruby-forum.com/t/calling-model-methods-even-when-the-param-is-a-not-set/129488 "2008-02-19T00:52:23Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![clemrock](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c57346/32.png) [@clemrock](https://www.ruby-forum.com/u/clemrock)\
**Post date:** [February 19, 2008, 12:52am UTC](https://www.ruby-forum.com/t/calling-model-methods-even-when-the-param-is-a-not-set/129488/1 "2008-02-19T00:52:23Z")

</div>

Hello,  
I’m setting a checkbox values based on the return of a model field  
method. The way the method is set up - it only gets called when a  
checkbox value is set.

Here’s the model code:

```auto
  def within=(new_within)
     @within = new_within == "1" || new_within == true || new_within ==
'true' || new_within == 'on'
  end
```

I would like that method to be called even when the checkbox is not set.

Thanks for any help anyone can provide.

Clem C

---

<div class="post-metadata">

**Author:** ![clemrock](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c57346/32.png) [@clemrock](https://www.ruby-forum.com/u/clemrock)\
**Post date:** [February 19, 2008, 2:09am UTC](https://www.ruby-forum.com/t/calling-model-methods-even-when-the-param-is-a-not-set/129488/2 "2008-02-19T02:09:00Z")

</div>

Could you provide me the check box script in view?

you can put additional params in form\_tag

example :

\<% from\_tag bla…bla…, :within =\> true %\>

…

\<% end\_from\_tag %\>

I hope it can answer yours. it will be directly executed each time the  
form\_tag is run. What do you want this ‘def within’ is run for every  
time model is used or only in form\_tag?

_~_~_~_~_~\*\*~_~_~_~_~_  
Reinhart Ariando  
YM : Booking2Heaven  
WEB : [http://teapoci.blogspot.com](http://teapoci.blogspot.com)

---

<div class="post-metadata">

**Author:** ![clemrock](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c57346/32.png) [@clemrock](https://www.ruby-forum.com/u/clemrock)\
**Post date:** [February 19, 2008, 6:20pm UTC](https://www.ruby-forum.com/t/calling-model-methods-even-when-the-param-is-a-not-set/129488/3 "2008-02-19T18:20:22Z")

</div>

Visit Indonesia 2008 wrote:

> Could you provide me the check box script in view?
> 
> you can put additional params in form\_tag
> 
> example :
> 
> \<% from\_tag bla…bla…, :within =\> true %\>
> 
> …
> 
> \<% end\_from\_tag %\>
> 
> I hope it can answer yours. it will be directly executed each time the  
> form\_tag is run. What do you want this ‘def within’ is run for every  
> time model is used or only in form\_tag?

Here’s the checkbox code:

\<input style=“height:13px;” id=“\<%= search\_obj %\>\_within” name=“\<%=  
search\_obj %\>[within]” type=“checkbox” \<%=  
!last\_search[:within].to\_s.blank? ? “checked=‘true’” : “” %\> value=“1”/\>

Also, here’s the form\_remote\_tag code:

\<%= form\_remote\_tag(:url =\> {:controller =\> ‘main’, :action =\> action},  
:html =\> { :id =\> “#{search\_obj}\_form”, :action =\> url\_for(:controller  
=\> ‘main’, :action =\> action) } ) %\>

I would like to have the def within to be run everytime the form\_tag is  
called.

I tried putting the :within =\> true in the form\_remote\_tag and had no  
results.

Thanks again for your help.

> _~_~_~_~_~\*\*~_~_~_~_~_  
> Reinhart Ariando  
> YM : Booking2Heaven  
> WEB : [http://teapoci.blogspot.com](http://teapoci.blogspot.com)

---

<div class="post-metadata">

**Author:** ![clemrock](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c57346/32.png) [@clemrock](https://www.ruby-forum.com/u/clemrock)\
**Post date:** [February 21, 2008, 12:28am UTC](https://www.ruby-forum.com/t/calling-model-methods-even-when-the-param-is-a-not-set/129488/4 "2008-02-21T00:28:13Z")

</div>

SHAMELESS BOOT!

Clem R. wrote:  
Visit Indonesia 2008 wrote:  
Could you provide me the check box script in view?

you can put additional params in form\_tag

example :

\<% from\_tag bla…bla…, :within =\> true %\>

…

\<% end\_from\_tag %\>

I hope it can answer yours. it will be directly executed each time the  
form\_tag is run. What do you want this ‘def within’ is run for every  
time model is used or only in form\_tag?

Here’s the checkbox code:

\<input style=“height:13px;” id=“\<%= search\_obj %\>\_within” name=“\<%=  
search\_obj %\>[within]” type=“checkbox” \<%=  
!last\_search[:within].to\_s.blank? ? “checked=‘true’” : “” %\> value=“1”/\>

Also, here’s the form\_remote\_tag code:

\<%= form\_remote\_tag(:url =\> {:controller =\> ‘main’, :action =\> action},  
:html =\> { :id =\> “#{search\_obj}\_form”, :action =\> url\_for(:controller  
=\> ‘main’, :action =\> action) } ) %\>

I would like to have the def within to be run everytime the form\_tag is  
called.

I tried putting the :within =\> true in the form\_remote\_tag and had no  
results.

Thanks again for your help.

_~_~_~_~_~\*\*~_~_~_~_~_  
Reinhart Ariando  
YM : Booking2Heaven  
WEB : [http://teapoci.blogspot.com](http://teapoci.blogspot.com)
