Commit cfa7fb3c authored by Milan's avatar Milan
Browse files

remove unneeded blogposts controller

parent 73d45b89
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/
// Place all the styles related to the blogposts controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
class BlogpostsController < ApplicationController
def index
@blogposts = Blogpost.all
end
def show
@blogposts = Blogpost.find(params[:id])
end
def new
@blogposts = Blogpost.new
end
def create
@blogposts = Blogpost.new(post_params)
@blogposts.save
redirect_to blogpost_path(@blogposts)
end
def edit
@blogposts = Blogpost.find(params[:id])
end
def update
@blogposts = Blogpost.find(params[:id])
@blogposts.update(post_params)
redirect_to blogpost_path(@blogposts)
flash.notice = "Article '#{@blogposts.title}' Updated!"
end
def destroy
@blogposts = Blogpost.find(params[:id])
@blogposts.destroy
redirect_to @blogposts
end
def post_params
params.require(:blogpost).permit(:title, :body)
end
end
<%= form_for @blogposts do |f| %>
<ul>
<% @blogposts.errors.full_messages.each do |error| %>
<li><%= error %></li>
<% end %>
</ul>
<p>
<%= f.label :title %><br />
<%= f.text_field :title %>
</p>
<p>
<%= f.label :body %><br />
<%= f.text_area :body %>
</p>
<p>
<%= f.submit %>
</p>
<% end %>
<% content_for :title, t('blogposts.edit.title') %>
<%= render partial: 'form' %>
<% content_for :title, t('blogposts.index.title') %>
<h1>All Posts</h1>
<ul id="posts">
<% @blogposts.each do |blogpost| %>
<li>
<%= link_to blogpost.title, blogpost_path(blogpost), class: 'post_title' %>
</li>
<% end %>
</ul>
<%= link_to "Create a New Post", new_blogpost_path, class: "new_post" %>
<% content_for :title, t('blogposts.new.title') %>
<h1>New Post</h1>
<%= render partial: 'form' %>
<% content_for :title, t('blogposts.show.title') %>
<div class="content">
<h2><%= @blogposts.title %></h2>
<p><%= markdown(@blogposts.body).html_safe %></p>
<hr>
<%= link_to t('blogposts.show.all_posts'), blogposts_path, class: "btn btn-default" %>
<%= link_to t('blogposts.show.edit_post'), edit_blogpost_path(@blogposts), class: "btn btn-info" %>
<%= link_to t('blogposts.show.delete_post'), blogpost_path(@blogposts), method: :delete, data: {confirm: t('blogposts.delete_post_confirm')}, class: "btn btn-danger" %>
</div>
require 'test_helper'
class BlogpostsControllerTest < ActionDispatch::IntegrationTest
# test "the truth" do
# assert true
# end
end
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment