Skip to content

Commit

Permalink
Article update options were completed
Browse files Browse the repository at this point in the history
 - Article was updated
 - Forms were simplified
  • Loading branch information
tayfunoziserikan committed Aug 17, 2014
1 parent bf6203e commit b58fd4f
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 35 deletions.
16 changes: 15 additions & 1 deletion app/controllers/articles_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,23 @@ def show
@article = Article.find(params[:id])
end

def new
def edit
@article = Article.find(params[:id])
end

def update
@article = Article.find(params[:id])

if @article.update(article_params)
redirect_to @article
else
render 'edit'
end
end

def new
@article = Article.new
end

def create

Expand Down
28 changes: 28 additions & 0 deletions app/views/articles/_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<%= 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 %>

<p>
<%= f.label :title %><br>
<%= f.text_field :title %>
</p>

<p>
<%= f.label :text %><br>
<%= f.text_area :text %>
</p>

<p>
<%= f.submit %>
</p>
<% end %>
5 changes: 5 additions & 0 deletions app/views/articles/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<h1>Editing article</h1>

<%= render 'form' %>

<%= link_to 'Back', articles_path %>
11 changes: 6 additions & 5 deletions app/views/articles/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
<h1>Listing Articles</h1>

<%= link_to 'New article', new_article_path %>

<table>
<tr>
<th>Title</th>
<th>Text</th>
<th colspan="2">Options</th>
</tr>

<% @articles.each do |article| %>
<tr>
<td><%= article.title %></td>
<td><%= article.text %></td>
<td><%= link_to 'Show', article_path(article) %></td>
<td><%= link_to 'Edit', edit_article_path(article) %></td>
</tr>
<% end %>
</table>

<p>
<%= link_to 'New article', new_article_path %>
</p>
</table>
29 changes: 1 addition & 28 deletions app/views/articles/new.html.erb
Original file line number Diff line number Diff line change
@@ -1,32 +1,5 @@
<h1>New Article</h1>

<%= form_for :article, url: articles_path 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 %>

<p>
<%= f.label :title %><br>
<%= f.text_field :title %>
</p>

<p>
<%= f.label :text %><br>
<%= f.text_area :text %>
</p>

<p>
<%= f.submit %>
</p>
<% end %>
<%= render 'form' %>

<%= link_to 'Back', articles_path %>
3 changes: 2 additions & 1 deletion app/views/articles/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@
<%= @article.text %>
</p>

<%= link_to 'Back', articles_path %>
<%= link_to 'Back', articles_path %>
| <%= link_to 'Edit', edit_article_path(@article) %>

0 comments on commit b58fd4f

Please sign in to comment.