class ProjectsController < ApplicationController
def create
@project = Project.create(name: params[:name])
@projects = Project.all
authorize(@project)
create.js.coffee
<% if @project.valid? %>
$('.tabs li').removeClass 'last'
$('.tabs').append '<li class=\"last\"><%= j(render @project) %></li>'
notice $('.project-<%= @project.id %>'), '#eaeaae'
$('.tabs input').val ''
<% else %>
notice $('.tabs input'), '#ff6666'
$('.tabs input').val ''
$('.tabs input').attr 'placeholder', '<%= @project.errors[:name].first %>'
<% end %>
index.html.slim
ul.tabs
li
= form_tag('/projects', method: :post, remote: true) do
= text_field_tag(:name, nil, placeholder: 'Новый проект')
- @projects.each_with_index do |project, index|
li[class="#{'active' if index == 0}#{' last' if index == @projects.size-1}"]
= render project