Answer the question
In order to leave comments, you need to log in
AJAX not working with Rails app?
And again, I continue the block of questions about Rails applications. There is a todo application, it displays a list of all Projects and tasks for them. Below there is a form for adding a new Project. I added format.js to the controller code
def create
@project = Project.new(project_params)
respond_to do |format|
if @project.save
format.html { redirect_to todo_path, notice: 'Project was successfully created.' }
=> format.js
format.json { render :show, status: :created, location: @project }
else
format.html { render :new }
format.json { render json: @project.errors, status: :unprocessable_entity }
end
end
end
<%= form_for(@project, remote: true) do |f| %>
<%= f.text_field :name, :placeholder => ' Enter new project here..' %>
<but><%= f.submit 'Add Project', remote: true %></but>
<% end %>
$('#projects').html("<%= escape_javascript render('projects') %>");
ActionView::Template::Error (Missing partial projects/_projects, application/_projects with {:locale=>[:en], :formats=>[:js, :html], :variants=>[], :handlers=>[:erb, :builder, :raw, :ruby, :jbuilder, :coffee]}. Searched in:
* "/home/xo8bit/ruby/todo-app/app/views"
):
1: $('#projects').html("<%= escape_javascript (render 'projects') %>");
app/views/projects/create.js.erb:1:in `_app_views_projects_create_js_erb__2233098556876763135_37757080'
app/controllers/projects_controller.rb:29:in `create'
Rendered /home/xo8bit/.rvm/gems/ruby-2.0.0-p481/gems/actionpack-4.1.4/lib/action_dispatch/middleware/templates/rescues/_trace.text.erb (1.0ms)
Rendered /home/xo8bit/.rvm/gems/ruby-2.0.0-p481/gems/actionpack-4.1.4/lib/action_dispatch/middleware/templates/rescues/_request_and_response.text.erb (1.4ms)
Rendered /home/xo8bit/.rvm/gems/ruby-2.0.0-p481/gems/actionpack-4.1.4/lib/action_dispatch/middleware/templates/rescues/template_error.text.erb (17.7ms)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question