forms - Rails: Keep params after a submit -
Suppose you had a web app, where people can add links, links to your website and website links, which they say are 'city. The submission form is the same in both cases, when they submit the domain of the link.
If the user is submitting from the list of their own registered websites, then they will receive a drop-down list of their websites.
If the user is submitting a link, then the user types the domain in an area whose value I get in the "link" model through attr_accessor. The "link" model then executes a find_or_create method on that domain.
My solution is unsatisfactory now: when the user clicks on "submit link", then I prompt = other in the URL and then conditionally:
& Lt;% If the consultation [: other] == "expedited"%> & Lt; Div class = "prompt_form" & gt; & Lt; H2 & gt; This link is for: & lt; / H2 & gt; & Lt; Span class = "blue_button" & gt; & Lt;% = link_to "My Website", new_link_path%> & Lt; / Span & gt; & Lt; Span class = "blue_button" & gt; & Lt;% = link_to "Other user's site", new_link_path (: other = & gt; "yes")% & gt; & Lt; / Span & gt; & Lt; / P & gt;
When a user creates an option differently between the two options in the form:
<% if the parameter [: other] == "Yes" || Current_user == zero% & gt; & Lt; Strong & gt; Website domain: & lt; / Strong> & Lt; Br / & gt; & Lt;% = f.text_field: unclaimed_domain% & gt; & Lt; Br / & gt; & Lt;% elsif current_user% & gt; & Lt;% If current_user.websites.size & gt; 1%> & Lt; P & gt; & Lt; Strong & gt; Website domain: & lt; / Strong> & Lt; Br / & gt; & Lt;% = f.collection_select: website_id, current_user.websites.valid ,: id, domain, {: include_blank = & gt; True}%> & Lt;% = error_message_on: link ,: website% & gt; & Lt; Br / & gt; & Lt;% = link_to "Add a website", new_website_path%> & Lt; / P & gt; & Lt;% else% & gt; & Lt; P & gt; & Lt; Strong & gt; Website domain: & lt; / Strong> & Lt; Br / & gt; & Lt;% = f.collection_select: website_id, current_user.websites.valid ,: id :: domain% & gt; & Lt; Br / & gt; & Lt;% = link_to "Add a website", new_website_path%> & Lt; / P & gt; & Lt;% end% & gt; The problem with this is that if the user makes an error and fails some assumptions, then "render: action => 'new' code is executed and in the parameter All information is lost, is lost. Is this a way to keep the information or maybe it is a different way of doing it?
I just have a rough understanding of your problem, but it seems that you want it :
& lt; input name = "other" value = "& lt;% = params [: other]%>" type = "hidden" & gt;
In this way, the current value of Other
will be resubmitted, and if verification fails, then it will still be accessible.