I am all new to rails, however quite familiar with “regular” MVC programming like Spring and .net. I am trying to cope with all this new way of doing stuff, but I keep getting stuck – especially when it comes to rendering/refreshing the same view with different data, based on a selection a user has made.
This is properly all really simple, and I can see it has been asked a lot of times – although, I cant seem to find any definite and “this is the rails way of doing it” answer.
All I want to do is the like this:
Database “scheme”, with table a,b,c and their references:
C -> A
C -> B
Based on a selection of B in a drop down, I want to show all the “A’s Cs” – dont mind the querying part, that is straight forward.
By now I choose the first B as a “first render” of the page in my controller, but when the user selects another B in the dropdown, the view should be rerendered based on the selection…
I dont want to use custom javascript filling or some other “weird” way. I must be possible to select something and refresh the view based on the selection in RoR.
I hope you either can help me or point me in the right direction.
Thanks!
Put all these select lists in a form and in the ‘onchange’ event of the lists add javascript that submits the form ($(‘form_name’).submit()). Once you submit the form, you have all the selected values as params (params[:select_list_1], params[:select_list_2]). Process them as you want, fire queries and display the view again.
You could submit the form to the same action. The action would be something like this:
EDIT (Form example): The form can be added as and :url specifies the action of form element: