# Conditon for button

**URL:** <https://www.ruby-forum.com/t/conditon-for-button/129635>\
**Category:** Rails\
**Created:** [February 20, 2008, 7:57am UTC](https://www.ruby-forum.com/t/conditon-for-button/129635 "2008-02-20T07:57:31Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![casid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/47e85d/32.png) [@casid](https://www.ruby-forum.com/u/casid)\
**Post date:** [February 20, 2008, 7:57am UTC](https://www.ruby-forum.com/t/conditon-for-button/129635/1 "2008-02-20T07:57:31Z")

</div>

hi everyone

I have two url\_to action, like this

converter: ‘\<%= url\_for :controller =\> ‘/project/report’, :action  
=\> ‘converter’ %\>’,

work\_sheet\_csv: ‘\<%= url\_for :controller =\> ‘/project/report’, :action  
=\> ‘work\_sheet\_csv’ %\>’,

and I have a selection like

 csv template\_of\_roster template\_of\_roster1 template\_of\_roster2 template\_of\_roster3 

I have a button and I want to write condition for two url. when I select  
csv and click button, want to run work\_sheet\_csv, when I select one of  
the templates, want to run converter.

how can I write condition for it.  
thanks for any help…

---

<div class="post-metadata">

**Author:** ![casid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/47e85d/32.png) [@casid](https://www.ruby-forum.com/u/casid)\
**Post date:** [February 20, 2008, 11:26am UTC](https://www.ruby-forum.com/t/conditon-for-button/129635/2 "2008-02-20T11:26:39Z")

</div>

Use select tag like this

select\_tag(‘id’, options\_for\_select([[foo],[bar]]),  
:onchange=\>remote\_function(:url =\>{:action =\> ‘yr\_rails\_method’},:with  
=\> “‘id=’+this.value”, :method=\>:post),:style =\> “width:  
220px;font-size: 90%;” )

in yr rails method u can check for the value("‘id=’+this.value") and  
redirect it.

All the best

---

<div class="post-metadata">

**Author:** ![casid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/47e85d/32.png) [@casid](https://www.ruby-forum.com/u/casid)\
**Post date:** [February 20, 2008, 8:45pm UTC](https://www.ruby-forum.com/t/conditon-for-button/129635/3 "2008-02-20T20:45:18Z")

</div>

Simplify your public interface and just use one action. Since  
converter handles most of the possibilities, I’d default to it and  
allow it to delegate to work\_sheet\_csv if necessary.

def convert  
work\_sheet\_csv and return if params[:tempates]==‘work\_sheet\_csv’  
… current convert code …  
end

private  
def work\_sheet\_csv  
…  
end

If that feels uncomfortable, then use a new action and let it simply  
delegate all the calls to either converter or work\_sheet\_csv as  
necessary.

On Feb 20, 1:57 am, Ibrahim D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![casid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/47e85d/32.png) [@casid](https://www.ruby-forum.com/u/casid)\
**Post date:** [February 21, 2008, 2:51am UTC](https://www.ruby-forum.com/t/conditon-for-button/129635/4 "2008-02-21T02:51:05Z")

</div>

Ratnavel S. wrote:

> Use select tag like this
> 
> select\_tag(‘id’, options\_for\_select([[foo],[bar]]),  
> :onchange=\>remote\_function(:url =\>{:action =\> ‘yr\_rails\_method’},:with  
> =\> “‘id=’+this.value”, :method=\>:post),:style =\> “width:  
> 220px;font-size: 90%;” )
> 
> in yr rails method u can check for the value("‘id=’+this.value") and  
> redirect it.
> 
> All the best

thank you very much for your help.  
I have a question to your suggestion. first I need to use the value of  
option  
because another method need it as well. another thing is that it s not  
object of form. selection is not used in form. lastly there will be  
button which should realize the selection and run the suitable url. as  
you see in selection there are some template names and work\_sheet\_csv. I  
will use another selection if I manage to get parameter from selection.

btw thank you very much for your help Ratnavel S…

---

<div class="post-metadata">

**Author:** ![casid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/47e85d/32.png) [@casid](https://www.ruby-forum.com/u/casid)\
**Post date:** [February 21, 2008, 4:03am UTC](https://www.ruby-forum.com/t/conditon-for-button/129635/5 "2008-02-21T04:03:43Z")

</div>

Ibrahim D. :

I advice you to paste your both of your controllers and index.rhtml  
using [http://pastie.caboo.se/](http://pastie.caboo.se/) and paste the links here, so they can  
understand the main your problem. I believe they can solve the problem  
if they can read your entire script, because your problem is how to call  
first the url of csv from your javascript function that you wrote in  
index.rhtml. I am not good in JS.

Reinhart Ariando

---

<div class="post-metadata">

**Author:** ![casid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/47e85d/32.png) [@casid](https://www.ruby-forum.com/u/casid)\
**Post date:** [February 21, 2008, 4:17am UTC](https://www.ruby-forum.com/t/conditon-for-button/129635/6 "2008-02-21T04:17:25Z")

</div>

Visit Indonesia 2008 wrote:

> Ibrahim D. :
> 
> I advice you to paste your both of your controllers and index.rhtml  
> using [http://pastie.caboo.se/](http://pastie.caboo.se/) and paste the links here, so they can  
> understand the main your problem. I believe they can solve the problem  
> if they can read your entire script, because your problem is how to call  
> first the url of csv from your javascript function that you wrote in  
> index.rhtml. I am not good in JS.
> 
> Reinhart Ariando

my problem is that get parameter from selection which is not in form  
object.

thank you very much for your help Reinhart Ariando. you spent your time  
for me.
