Last active
December 19, 2015 02:59
-
-
Save gkilmain/5887222 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
projects/index | |
<h1>Listing projects</h1> | |
<br /> | |
<div id="projects_list"> | |
<% @projects.each do |project| %> | |
<%= project.name %><br> | |
<% end %> | |
</div> | |
<%= link_to 'New Project', new_project_path, id: 'new_link', remote: true %> | |
======================================= | |
projects/new.js.erb | |
$('#new_link').hide().after('<%= j render("form")%>'); | |
======================================= | |
projects/_form.html.erb | |
<%= form_for(@project, remote: true) do |f| %> | |
<% if @project.errors.any? %> | |
<div id="error_explanation"> | |
<h2><%= pluralize(@project.errors.count, "error") %> prohibited this project from being saved:</h2> | |
<ul> | |
<% @project.errors.full_messages.each do |msg| %> | |
<li><%= msg %></li> | |
<% end %> | |
</ul> | |
</div> | |
<% end %> | |
<div class="field"> | |
<%= f.label :name %><br /> | |
<%= f.text_field :name %> | |
</div> | |
<div class="actions"> | |
<%= f.submit %> | |
</div> | |
<% end %> | |
========================================= | |
projects/create.js.erb | |
$('#new_project').hide(); | |
$('#new_link').show(); | |
$('#projects_list').append('<%= j render(@project) %>'); // THIS IS WHERE I"M GETTING THE 500 error | |
========================== | |
ProjectsController | |
class ProjectsController < ApplicationController | |
# GET /projects | |
# GET /projects.json | |
def index | |
@projects = Project.all | |
respond_to do |format| | |
format.html # index.html.erb | |
format.json { render json: @projects } | |
end | |
end | |
# GET /projects/1 | |
# GET /projects/1.json | |
def show | |
@project = Project.find(params[:id]) | |
respond_to do |format| | |
format.html # show.html.erb | |
format.json { render json: @project } | |
end | |
end | |
# GET /projects/new | |
# GET /projects/new.json | |
def new | |
@project = Project.new | |
respond_to do |format| | |
format.html # new.html.erb | |
format.json { render json: @project } | |
format.js | |
end | |
end | |
# GET /projects/1/edit | |
def edit | |
@project = Project.find(params[:id]) | |
end | |
# POST /projects | |
# POST /projects.json | |
def create | |
@project = Project.new(params[:project]) | |
respond_to do |format| | |
if @project.save | |
format.html { redirect_to @project, notice: 'Project was successfully created.' } | |
format.json { render json: @project, status: :created, location: @project } | |
format.js | |
else | |
format.html { render action: "new" } | |
format.json { render json: @project.errors, status: :unprocessable_entity } | |
format.js | |
end | |
end | |
end | |
# PUT /projects/1 | |
# PUT /projects/1.json | |
def update | |
@project = Project.find(params[:id]) | |
respond_to do |format| | |
if @project.update_attributes(params[:project]) | |
format.html { redirect_to @project, notice: 'Project was successfully updated.' } | |
format.json { head :no_content } | |
else | |
format.html { render action: "edit" } | |
format.json { render json: @project.errors, status: :unprocessable_entity } | |
end | |
end | |
end | |
# DELETE /projects/1 | |
# DELETE /projects/1.json | |
def destroy | |
@project = Project.find(params[:id]) | |
@project.destroy | |
respond_to do |format| | |
format.html { redirect_to projects_url } | |
format.json { head :no_content } | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment