Thursday, 15 August 2013

Rails form_for in Twitter Bootstrap Modal with AJAX/JSON -


I have a problem in the form of rail form for the form to work in the bootstrap model and to update a table with AJAX is. I have followed the guide, there is no benefit. I have also tried to follow the advice given in the links at the bottom of this question.

On the index view, I have a driver and have a button to add a new driver. The button brings the model to a new driver with a form. When the form is deposited, I want to close the model and the new driver appears alphabetically in the driver table. Now what is happening is that the model comes up and shows the form, but clicking on the submit button does not stop the modal and the new driver is not added to the database.

Here's a summary of app / view / driver / index.html.erb :

  & lt; Div & gt; & Lt; A href = "#deviceadmodal", role = "button", class = "btn btn-medium btn-primary", data-toggle = "modal" & gt; Add driver & lt; / A & gt; & Lt;% = Render 'new_driver'% & gt; & Lt; / Div & gt; & Lt; Div & gt; & Lt; Table id = "driver" category = "table-table-hover" & gt; & Lt; Thead & gt; & Lt;% = Render 'list_header'% & gt; & Lt; / Thead & gt; & Lt; Tbody & gt; & Lt;% = render @ drivers.sort_by (and: last_name)% & gt; & Lt; / Tbody & gt; & Lt; / Table & gt; & Lt; / Div & gt; Modal is partial on   

here App / Scene / Driver / _new_driver.html.erb :

  & lt; Div id = "driver additional model", class = "modal hide fade" & gt; & Lt; Div class = "modal-header" & gt; & Lt; Button type = "button" class = "off" data-rejected = "modal" Aria-hidden = "true" & gt; And;; & Lt; / Button & gt; & Lt; H3 id = "driverAddModalLabel" & gt; Add driver & lt; / H3 & gt; & Lt; / Div & gt; & Lt; Div class = "modal-body" & gt; & Lt;% = form_for @driver, Remote: True Do | F | & Gt%; Last name & lt;% = f.text_field: last_name% & gt; & Lt ;! - More form fields - & gt; & Lt;% = f.submit "Add Driver", Category: "BTN BTN-BTN-Primary"%> & Lt;% end% & gt; & Lt; / Div & gt; & Lt; / Div & gt;   

App / Controller / Driver_Controller RB :

  class driver communicator & lt; ApplicationController def new @driver = driver. Make a new end DRF @ Driver = Driver. New (Param [: Driver]) response_to do | Format | If @driver.save format.html {redirect_to @driver, notice: 'driver added.' } Format.js {} format.json {render json: @driver, position :: created, location: @driver} and format.html {action: "new"} format.json {json: @driver.errors, status: : Unprocessable_entity} End end end DEF index @ driver = driver. NY @ Drawers = Driver. All answers do not do it. Format | Format.html End End   

App / Ideas / Drivers / create.js.erb :

  $ (" Lt;% = Escape_javascript (render @ driver)%>) Apendoto ("#driver");   

App / assets / javascript / drivers. Js.coffee :

  $ (document) .ready - & gt; $ ("#New_driver"). ("Ejax: success", (e, data, position, xhr) -> gtc: $ ("# new_driver") .append xhr.responseText .bind "ajax: error", (e, exhaor, status, error) - & gt; $ ("#New_driver"). Add "& lt; p & gt; ERROR & lt; / p & gt;" Unfortunately, I do not know how to apply advice on those pages on my app. I am normally new to rail and programming and this is my first AAAx or JSON climb.   

It seems that you are very new to the railways. In your case, I suggest that when you submit the form you read and read the log files and also log the parameter [: Driver] to see that all the fields are there, and the verification of your model See for After Driver.errors.inspect says that the reason for verification is due.

Yoga:

  1. Check the logs if there is a request to make your controller.
  2. Output all the parameters to present everything as expected.
  3. Output 'success' and output driver in the field of success. / Ol>

    Then you are good to see all the bugs.

    Oh, I recommend that you see the rail crast, they got everything there.

1 comment:

  1. Giuseppe: Rails Form_For In Twitter Bootstrap Modal With Ajax/Json - >>>>> Download Now

    >>>>> Download Full

    Giuseppe: Rails Form_For In Twitter Bootstrap Modal With Ajax/Json - >>>>> Download LINK

    >>>>> Download Now

    Giuseppe: Rails Form_For In Twitter Bootstrap Modal With Ajax/Json - >>>>> Download Full

    >>>>> Download LINK Gt

    ReplyDelete