HTML button is not submitting form - ruby-on-rails

I have an issue in which my html form button is not submitting form or redirecting to the specified controller method named "record".
This is the form page with POST method and action named "/record"
Thats the highlighted post route path
And thats the controller method

Related

Submit a form from different page

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.

can <s:action> tag submit action as POST?

I have restriction in our application that if action declared as GET then only those action can be submit as GET method.
I want to know that can we submit s:action as POST method??
If Yes then please give me the guidance.
If not then what is the proper way to get call action from JSP and need the result in that JSP and the action should be post.
If you were doing this without Struts at all, your question would be: Can I submit an HTML form with an HTTP POST method. Obviously, the answer is yes, simply add the method="POST" attribute to your form tag.
In Struts, you get the same behavior from the struts form tag (described here: https://struts.apache.org/docs/form.html). In that doc, it shows that there is no default for the method attribute, but I would expect that to actually be the same as the default for the HTML form method - GET. If you provide a struts form tag with a method="POST" you should be set.

Determining controller based on post data in Rails

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.

AJAX calls action for a partial?

I have a page show.html.erb with a corresponding action 'show'. Lower on the page, a partial is loaded called _filter.html.erb which contains undefined instances (so basically, on the initial load, nothing is displayed there).
In the show.html.erb, I have a form that uses AJAX and submits to an action called "filter" which is supposed to create some instances for use within the _filter partial (so now, the _filter partial within show will have some content).
But when i submit the form, it says Template is missing Missing template results/filter.
But what it should be doing is staying on the same current template (show.html.erb) and just run the filter action and update the partial _fitler.
Any suggestions?
UPDATE
Following some things i found online, i made a file _filter.js.erb withing the views/results directory (same dir as show.html.erb and _filter.html.erb):
$("filter").update("<%= escape_javascript(render("filter"))%>");
But it doesnt seem to be doing anything..
By rails convention if you use the name _filter then you should put this file in shared folder.
So it's should be shared/_filter.html.erb

Render another controllers view as partial (Rails 3)

Sorry, only have been using rails for 10 day and I'm completely lost. Have a post model/controller and comment model/controller.
In post/show, I want to click an ajax button and replace a div (#addcomment) with the partial generated from comment/new (The new action takes two params and builds a comment for an ajax form partial). The comment/new partial is an add comment form with remote => true.
Anyone willing to point me in the right direction?
Tried using an ajax button in the view, that calls an action that replaces the div with the comment/new but it didn't work.

Resources