diff --git a/app/controllers/articles_controller.rb b/app/controllers/articles_controller.rb index c4d9a5e..0a79954 100644 --- a/app/controllers/articles_controller.rb +++ b/app/controllers/articles_controller.rb @@ -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 diff --git a/app/views/articles/_form.html.erb b/app/views/articles/_form.html.erb new file mode 100644 index 0000000..cadd083 --- /dev/null +++ b/app/views/articles/_form.html.erb @@ -0,0 +1,28 @@ +<%= form_for @article do |f| %> + + <% if @article.errors.any? %> +
+ <%= f.label :title %>
+ <%= f.text_field :title %>
+
+ <%= f.label :text %>
+ <%= f.text_area :text %>
+
+ <%= f.submit %> +
+<% end %> \ No newline at end of file diff --git a/app/views/articles/edit.html.erb b/app/views/articles/edit.html.erb new file mode 100644 index 0000000..b5a6f17 --- /dev/null +++ b/app/views/articles/edit.html.erb @@ -0,0 +1,5 @@ +Title | Text | +Options | |
---|---|---|---|
<%= article.title %> | <%= article.text %> | +<%= link_to 'Show', article_path(article) %> | +<%= link_to 'Edit', edit_article_path(article) %> |
- <%= link_to 'New article', new_article_path %> -
+ \ No newline at end of file diff --git a/app/views/articles/new.html.erb b/app/views/articles/new.html.erb index 205340e..505675b 100644 --- a/app/views/articles/new.html.erb +++ b/app/views/articles/new.html.erb @@ -1,32 +1,5 @@
- <%= f.label :title %>
- <%= f.text_field :title %>
-
- <%= f.label :text %>
- <%= f.text_area :text %>
-
- <%= f.submit %> -
-<% end %> +<%= render 'form' %> <%= link_to 'Back', articles_path %> \ No newline at end of file diff --git a/app/views/articles/show.html.erb b/app/views/articles/show.html.erb index 7361686..c0358fc 100644 --- a/app/views/articles/show.html.erb +++ b/app/views/articles/show.html.erb @@ -10,4 +10,5 @@ <%= @article.text %> -<%= link_to 'Back', articles_path %> \ No newline at end of file +<%= link_to 'Back', articles_path %> +| <%= link_to 'Edit', edit_article_path(@article) %> \ No newline at end of file