Executive Summary
- I have Bootstrap Modal on a Rails 4 Server I have created
- This Modal is used to submit a NEW post via remote: true
- I get an error during the Form Submission saying remote true doesn't work.
- The form can actually submit successful WITHOUT the remote true but it isn't ajax.
- What is wrong with my remote: true line. It is a direct cut and paste.
Dear Friends,
So I have been spending two days on this problem. I have a Bootstrap Modal that I want to use to allow for new submissions. I want this to be done via ajax, and from all the documentation form_for() object should be passed at :remote => true.
I am able to get my form to work without the remote true enabled, but when I place it in my form_for, It no longer works and I get a syntax error as listed below.
Please help.
applicaton.html.erb in Layouts
<%= stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true %>
<%= javascript_include_tag "application", "data-turbolinks-track" => true %>
application.js
//= require jquery
//= require bootstrap-sprockets
//= require jquery_ujs
//= require turbolinks
//= require masonry/jquery.masonry
//= require masonry/jquery.infinitescroll.min
//= require_tree .
This is the HTML file that generates the Modal
<div id="largeModal" class="modal fade bs-example-modal-lg" tabindex="-1" role="dialog">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title">Submission</h4>
</div>
<div class="modal-body">
<%= render 'formnew' %>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
</div>
</div>
</div>
</div>
Here is my formnew.html.erb (This is where the problem is)
<%= form_for (@item, remote: true) do |f| %>
<% if @item.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@item.errors.count, "error") %> prohibited this item from being saved:</h2>
<ul>
<% @item.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="form-group">
<%= f.label :title %><br>
<%= f.text_area :title, {:class=> "form-control", :size => "30x10"} %>
</div>
<div class="form-group">
<%= f.label :subject %><br>
<%= f.text_area :subject, {:class=> "form-control", :size => "30x10"} %>
</div>
<div class="form-group">
<table class= "table-bordered">
<tbody>
<tr>
</tr>
</tbody>
</table>
</div>
<div class=" form-actions">
<%= f.submit %>
</div>
<% end %>
ERROR that i recieve that I can't figure out (btw it works without the REMOTE command)
/home/vic/projects/projects/app/views/projects/_formnew.html.erb:2: syntax error, unexpected ',', expecting ')' ...fer.append= form_for (@item, remote: true) do |f| @output... ... ^
Here is my Controller
def index
@item = Item.new
page = params[:page]
if(page.blank? == false)
next_page =(page.to_i)
else
page = 0;
next_page = page+1
end
@objects = Object.paginate(page: next_page, per_page: 20).order("created_at DESC")
@next_link = next_page +1
respond_to do |format|
format.json { render :show, status: :created, location: @item }
format.html {render :index}
format.js {}
end
end
html
code in theapplication.js
or it is typo? – Philidor