I am new to ruby on rails.
I have a form say form1.On clicking the submit button this form should take me to another form with the parameters passed.Please let me know how to do it and also how to access the form1 parameters in form2.
If you mean a multistep form, check out: http://railscasts.com/episodes/217-multistep-forms
The basic concept is that you will have to set the url to post to in your form tag (the default is a create or update action). Once in your new controller action, your previous form is available in the params hash. Without more details on your question, we can't provide better details.
Related
I have a Driver form (which is basically the user - I can do current_driver and stuff) and one of the fields is a boolean checkbox for 'subscribe to newsletter'.
I want to put this form on multiple pages that do not share the same controller, i.e Dashboard which has a pages controller.
I am using a partial to do this so i can just add the partial to a template easily.
I believe that the form should post to edit_driver_path as it's the driver form? At the moment when I submit the form, I get "No route matches [POST] "/drivers/dashboard/edit".
Am I on the right path here?
Let me know if I need to post controllers, forms or whatever.
In my Rails application I have a form with radio type inputs and post method. The user selects one of these radio options and submits the form. How could I set the routing such (in routes.rb or in some other way) that the controller would be selected based on the value of the selected input value which is now in the post data. In routes.rb the params hash isn't available, but could I access this data in some other way?
Two options come to my mind:
Use JavaScript to intercept the submit action. On submit, read the value of the selected radio option, change the target attribute of the form to the URL you expect to be used and submit the form.
To make the JavaScript unobtrusive, the URL of the target can be added as a data-target attribute to the radio options. In this way, once you get the selected value, you just replace the form target with the value of data-target. The benefit is that you can generate it server side and you don't have to hard-code the value.
Use an intermediate action. Always submit the form to an action that reads the payload and redirects to the relevant controller action based on the payload value.
In Rails, when you go to the edit action, it automatically pulls the information from the models and populates the form. If I had a CRUD that saves sensitive information, for example password or ssn, how can I filter the values so that it doesn't just show it in plaintext when editing the form?
I was going to change the value in the controller by setting it to ****, but the potential risk there is people may submit the form and it will update the SSN to ****.
I'm not referring to filtering the params so it doesn't show up in console (config.filter_parameters).
Changing the input field to type="password" should resolve your problem. Just don't set the fields in the controller if they are blank.
If you are using a form builder, change text_field to password_field.
I have the following relation in my model:
A user can have several consumers
According to that, I call several actions from different controllers that depend on that consumer_id in the URL. So, I do stuff like:
/:consumer_id/products/all
/:consumer_id/locals/all?params...
I want to be able to given that I am in a particular view, let's say /3/products/all, be able to refresh, redirect or whatever is the best to /4/products/all, with a form that shows the different consumers attached to that user.
I know how to display the form, but I fail to see which action should I put given that I want to load the current controller, current action and the current params, except that I want to change the params[:consumer_id] and the session[:consumer_id] to the one chosen by the user in the form of the view.
What's the best or appropriate way of doing so?
This is a link to the same page with the same parameters and one additional parameter:
<%= link_to "Show more results", url_for(params.merge(:per => 100)) %>
If you want to modify a parameter rather than add a new one, you can modify the params hash just as you would modify any hash, and use url_for again.
Inside the view you can access both the current controller using controller_name and the current action using action_name
Your question is not clear. You want to choose consumer_id from your form, then use that consumer id inside the same page or for links to other pages?
If you want to use the consumer id for the current page, you need to use javascript or JQuery to update all attributes of the current page.
If you want to use that consumer id for links,
you may also use JQuery to update all links on your page
Or, you can submit the form to the server with new consumer_id.
I'm new at ruby on rails, and I wanted to accomplish the following:
I've got a list with check boxes(one per row) and I'd like to have a link button(not a common button or submit) so when I click it I call an action from a controller.
My questions are:
How can I call a controller action with the link_to?
How do I get the checkboxes values(which of them are checked) and fields' values so I can know to whom apply the action? I'm used to work with C#, and there the lists have an ItemDataBound method in where you can get easily every row lets say, but I can't figure anything similar here.
If it's not clear enough, I'm going to put an example:
Let's say I've got the following "screen":
Delete(link)
Article ID | Article Name
chkbox 1111 t-shirt
chkbox 2222 pants
chkbox 3333 boots
Now, let's say I'd like to delete the pants and boots. So I'll check their check boxes and then I'll press Delete. Now, I'd like to have at my Articles controller, at the method delete_article(for example) and then get the id and name for those checked articles, and delete them.
Thanks,
Brian
I would wrap the checkboxes in a form and then submit this form using the link (either with javascript or change the link to a form button and style as a link).
Rails assumes a RESTful approach out of the box, so a straight link will always hit a GET accessible action on your controller (generally index or show). GET actions should always be idempotent.
You can use link_to the standard way, check out the rails documentation on 'link_to'.
The values from checkboxes can be get from the params hash.
Just look out for the documentation.