just a quick dropdown box question

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

just a quick dropdown box question

Joe Guerra
I'm going to add a filter to a page index,  with the options of [both, true, false].

Do I need to add a button beside the dropdown to refresh the page, or can it pick out the changes made to the dropdown itself (or is that some sort of javascript stuff?)

Thanks,
Joe


--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/d9fee589-42ab-4eb6-af26-70bbd25ba26c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: just a quick dropdown box question

Walter Lee Davis

> On Oct 29, 2018, at 3:32 PM, Joe Guerra <[hidden email]> wrote:
>
> I'm going to add a filter to a page index,  with the options of [both, true, false].
>
> Do I need to add a button beside the dropdown to refresh the page, or can it pick out the changes made to the dropdown itself (or is that some sort of javascript stuff?)
>
> Thanks,
> Joe
>

This is basic HTML stuff, but if you have a form input like a dropdown (select), the value you choose in that element is only sent to the server if it is inside a form element, and you submit that form in some way to the server. On the server, you need to permit that attribute in strong parameters, so it won't be filtered out, and then use that in your controller method to act as your filter.

Whether you submit the form via JavaScript or add a submit button and have the user press it makes no difference to the server.

If you're on an index page, say www.example.com/pages, then you can code the form like this:

<%= form.for url: '/pages', method: :get do |f| %>

<%= f.collection_select :filter, %w[both true false], :to_s, :to_s, onchange: "this.form.trigger('submit')", prompt: true  %>

<%- end -%>

That's going to submit to your controller in the index method, where I presume you will do the rest.

Walter

>
>
> --
> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
> To post to this group, send email to [hidden email].
> To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/d9fee589-42ab-4eb6-af26-70bbd25ba26c%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/607AEDAA-0378-4071-9514-3D7FF5DDEF44%40wdstudio.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: just a quick dropdown box question

Joe Guerra
hmm, I thought a select_tag would work?

how do you handle the option on the controller?

On Monday, October 29, 2018 at 10:05:09 PM UTC-4, Walter Lee Davis wrote:

> On Oct 29, 2018, at 3:32 PM, Joe Guerra <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="ZgHm6j27BgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">jgu...@...> wrote:
>
> I'm going to add a filter to a page index,  with the options of [both, true, false].
>
> Do I need to add a button beside the dropdown to refresh the page, or can it pick out the changes made to the dropdown itself (or is that some sort of javascript stuff?)
>
> Thanks,
> Joe
>

This is basic HTML stuff, but if you have a form input like a dropdown (select), the value you choose in that element is only sent to the server if it is inside a form element, and you submit that form in some way to the server. On the server, you need to permit that attribute in strong parameters, so it won't be filtered out, and then use that in your controller method to act as your filter.

Whether you submit the form via JavaScript or add a submit button and have the user press it makes no difference to the server.

If you're on an index page, say <a href="http://www.example.com/pages" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwww.example.com%2Fpages\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHwCpjRA1aqB9hAAC0oJfnOkUvAWQ&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwww.example.com%2Fpages\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHwCpjRA1aqB9hAAC0oJfnOkUvAWQ&#39;;return true;">www.example.com/pages, then you can code the form like this:

<%= form.for url: '/pages', method: :get do |f| %>

<%= f.collection_select :filter, %w[both true false], :to_s, :to_s, onchange: "this.form.trigger('submit')", prompt: true  %>

<%- end -%>

That's going to submit to your controller in the index method, where I presume you will do the rest.

Walter

>
>
> --
> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="ZgHm6j27BgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">rubyonrails-ta...@googlegroups.com.
> To post to this group, send email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="ZgHm6j27BgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">rubyonra...@googlegroups.com.
> To view this discussion on the web visit <a href="https://groups.google.com/d/msgid/rubyonrails-talk/d9fee589-42ab-4eb6-af26-70bbd25ba26c%40googlegroups.com" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/msgid/rubyonrails-talk/d9fee589-42ab-4eb6-af26-70bbd25ba26c%40googlegroups.com&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/msgid/rubyonrails-talk/d9fee589-42ab-4eb6-af26-70bbd25ba26c%40googlegroups.com&#39;;return true;">https://groups.google.com/d/msgid/rubyonrails-talk/d9fee589-42ab-4eb6-af26-70bbd25ba26c%40googlegroups.com.
> For more options, visit <a href="https://groups.google.com/d/optout" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;">https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/8b1126ba-e512-4bcd-a5ff-a941d646a632%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.