Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/controllers/articles_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def update

respond_to do |format|
if @article.update_attributes(params[:article])
format.html { redirect_to(@article, :notice => 'Article was successfully updated.') }
format.html { redirect_to(articles_path, :notice => 'Article was successfully updated.') }
format.xml { head :ok }
else
format.html { render :action => "edit" }
Expand Down
2 changes: 1 addition & 1 deletion app/views/articles/_article.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<tr>
<td><%= article.title %></td>
<td><%= link_to 'Show', article %></td>
<td><%= link_to 'Edit', edit_article_path(article) %></td>
<td><%= link_to 'Edit', edit_article_path(article), :class => 'modal' %></td>
<td><%= link_to 'Destroy', article, :confirm => 'Are you sure?', :method => :delete %></td>
</tr>
21 changes: 21 additions & 0 deletions app/views/articles/_update-form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<%= form_for @article do |f| %>
<% if @article.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@article.errors.count, "error") %> prohibited this article from being saved:</h2>

<ul>
<% @article.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>

<div class="field">
<%= f.label :title %><br />
<%= f.text_field :title %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
1 change: 1 addition & 0 deletions app/views/articles/create.js.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
$('#dialog-form').dialog('close');
$('#dialog-form').remove();
$('table').append('<%= escape_javascript(render(@article)) %>');
$('table tr:last .modal').click(attatchModal());
<%- end %>
10 changes: 6 additions & 4 deletions app/views/articles/edit.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<h1>Editing article</h1>
<div id="content">
<h1>Editing article</h1>

<%= render 'form' %>
<%= render 'update-form' %>

<%= link_to 'Show', @article %> |
<%= link_to 'Back', articles_path %>
<%= link_to 'Show', @article %> |
<%= link_to 'Back', articles_path %>
</div>
2 changes: 1 addition & 1 deletion app/views/articles/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@

<br />

<%= link_to 'New Article', new_article_path, :id => 'create_article' %>
<%= link_to 'New Article', new_article_path, :class => 'modal' %>
12 changes: 9 additions & 3 deletions public/javascripts/application.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults

$(document).ready(function() {
$('#create_article').click(function(e) {
function attatchModal() {
$('.modal').click(function(e) {
var url = $(this).attr('href');
var dialog_form = $('<div id="dialog-form">Loading form...</div>').dialog({
autoOpen: false,
width: 520,
modal: true,
show: 'fade',
hide: 'drop',
open: function() {
return $(this).load(url + ' #content');
},
Expand All @@ -18,4 +20,8 @@ $(document).ready(function() {
dialog_form.dialog('open');
e.preventDefault();
});
});
}

$(document).ready(function() {
attatchModal();
});