에피소드 http://railscasts.com/episodes/136-jquery-ajax-revised 에 이어 내 cusotm 예제를 만들었습니다. 색인에 작성 양식을 작성하고 원격 메소드로 책을 만듭니다.레일즈에서 ujs를 사용하는 원격 메소드로 양식의 메시지 표시
그러나 페이지에 오류 메시지를 삽입하는 방법을 모릅니다. 좀 예를 들어주세요, 감사합니다 ~
인덱스
<%= render 'form' %>
<p>
<table id='books_tbl' class="table">
<th>id</th>
<th>title</th>
<th>ISBN</th>
<th>sn</th>
<th>price</th>
<th>Functions</th>
<div class="books" id="books">
<%= render @existed_books %>
</div>
</table>
컨트롤러는
# POST /books
# POST /books.json
def create
@book = Book.new(params[:book])
respond_to do |format|
if @book.save
format.html { redirect_to @book, notice: 'Book was successfully created.' }
format.json { render json: @book, status: :created, location: @book }
format.js
else
format.html { render action: "new" }
format.json { render json: @book.errors, status: :unprocessable_entity }
format.js
end
create.je.erb
<% unless @book.save %>
<% else %>
$('#books_tbl tr:last').after('<%= j render(@book) %>');
<% end %>
감사합니다 ~ 작동 – newBike