Skip to content
Open
Show file tree
Hide file tree
Changes from 8 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
10 changes: 5 additions & 5 deletions app/controllers/ad_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,26 @@ def new
def create
@ad = Ad.new(ad_params)
if @ad.save # 広告登録成功時
flash[:notice] = 'Ad registered!'
flash[:notice] = '広告を登録しました!'
redirect_to(ad_index_path)
else
render('ad/new')
render(new_ad_path)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

render('new') で行けたらそれで

end
end

def update
@ad = Ad.find(params[:id])
if @ad.update_attributes(ad_params)
flash[:notice] = 'Ad updated!'
flash[:notice] = '広告を更新しました!'
redirect_to(ad_index_path)
else
render('ad/edit')
render('edit')
end
end

def destroy
Ad.find(params[:id]).destroy
flash[:notice] = 'Ad deleted!'
flash[:notice] = '広告を削除しました!'
redirect_to(ad_index_path)
end

Expand Down
3 changes: 0 additions & 3 deletions app/jobs/application_job.rb

This file was deleted.

2 changes: 1 addition & 1 deletion app/views/ad/_errorlog.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<% if @ad.errors.any? %>
<% @ad.errors.full_messages.each do |error| %> <%# formが空白だった場合にエラーを表示 %>
<li><%= error %></li>
<li class="h2"><%= error %></li>
<% end %>
<% end %>
12 changes: 6 additions & 6 deletions app/views/ad/edit.html.erb
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<%= render partial: "errorlog" %>
<%= form_for(@ad ,url: ad_path(@ad),html: {method: "patch",class: "form-group"}) do |f| %> <%##入稿フォーム %>
<div class="form-group">
<p>text</p>
<div class="form-group h3">
<p>広告文</p>
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ここは「テキスト」いいよ

<%= f.text_area :text,value: @ad.text,class: "form-control" %>
<p>price</p>
<p>単価</p>
<%= f.number_field :price,value: @ad.price %>
<p>advertiser_id</p>
<p>広告主ID</p>
<%= f.number_field :advertiser_id,value: @ad.advertiser_id %>
<p>image</p>
<p>イメージ</p>
<%= f.file_field :image,value: @ad.image,class: "form-control-file" %>
<%= f.submit class: "btn btn-primary",value: "更新" %>
<%= f.submit class: "btn btn-primary h2",value: "更新" %>
</div>
<% end %>
60 changes: 36 additions & 24 deletions app/views/ad/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,27 +1,39 @@
<div class="ads">
<div class="each_ad"> <%# 広告を一つ一つ表示 %>
<% @ads.each do |ad| %>
<li>
<span>ad_id :<%= ad.id %></span>
</li>
<li>
<span>text :<%= ad.text %></span>
</li>
<li>
<span>price :<%= ad.price %></span>
</li>
<li>
<%= image_tag ad.image.to_s %>
</li>
<div class="edit_button">
<%= link_to("Edit", edit_ad_path(ad)) %>
</div>
<div class="delete_button">
<%= link_to("Delete", ad_path(ad) ,method: :delete) %>
</div>
<% end %>
<div>
<%= link_to("New", new_ad_path) %>
</div>
<div class="links">
<p class="h2">
<%= link_to("新規作成", new_ad_path) %>
<!-- Reportへのリンクは他Branch(feature_adreport)で挿入します -->
</p>
</div>

<table class="table">
<thead class="thead-dark">
<tr>
<th scope="col" class="h2">広告ID</th>
<th scope="col" class="h2">広告主ID</th>
<th scope="col" class="h2">広告文</th>
<th scope="col" class="h2">単価</th>
<th scope="col" class="h2">イメージ画像</th>
<th scope="col" class="h2">操作</th>
</tr>
</thead>
<tbody>
<tr>
<% @ads.each do |ad| %><%# 広告を一つ一つ表示 %>
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

コメント不要(処理見れば何やってるかわかる)

<td class="h3 align-middle"><%= ad.id %></td>
<td class="h3 align-middle"><%= ad.advertiser_id %></td>
<td class="h3 align-middle"><%= ad.text %></td>
<td class="h3 align-middle"><%= ad.price %></td>
<td class="h3 align-middle"><%= image_tag ad.image.to_s %></td>
<td ><p class="edit_button h4">
<%= link_to("変更", edit_ad_path(ad)) %>
</p>
<p class="delete_button h4">
<%= link_to("削除", ad_path(ad) ,method: :delete) %>
</p>
</td>
</tr>
<% end %>
</tbody>
</table>
</div>
12 changes: 6 additions & 6 deletions app/views/ad/new.html.erb
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<%= render partial: "errorlog" %>
<%= form_for(@ad ,url: ad_index_path,html: {method: "post",class: "form-group"}) do |f| %> <%##入稿フォーム %>
<div class="form-group">
<p>text</p>
<div class="form-group h3">
<p>広告文</p>
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

「テキスト」でよろしく

<%= f.text_area :text,value: @ad.text,class: "form-control" %>
<p>price</p>
<p>単価</p>
<%= f.number_field :price,value: @ad.price %>
<p>advertiser_id</p>
<p>広告主ID</p>
<%= f.number_field :advertiser_id,value: @ad.advertiser_id %>
<p>image</p>
<p>イメージ</p>
<%= f.file_field :image,value: @ad.image,class: "form-control-file" %>
<%= f.submit class: "btn btn-primary",value: "入稿" %>
<%= f.submit class: "btn btn-primary h2",value: "入稿" %>
</div>
<% end %>
8 changes: 0 additions & 8 deletions db/migrate/20190604073026_add_report_column_to_ads.rb

This file was deleted.

5 changes: 1 addition & 4 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,13 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 2019_06_04_073026) do
ActiveRecord::Schema.define(version: 2019_05_28_085221) do
create_table 'ads', force: :cascade do |t|
t.integer 'advertiser_id', default: 0, null: false
t.string 'image', default: '', null: false
t.integer 'price', default: 0, null: false
t.string 'text', default: '', null: false
t.datetime 'created_at', null: false
t.datetime 'updated_at', null: false
t.integer 'click'
t.integer 'imp'
t.integer 'cv'
end
end
11 changes: 4 additions & 7 deletions spec/controllers/ad_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@
'price' => nil,
'advertiser_id' => nil,
'image' => nil
},
id: @ad.id }
}, id: @ad.id }
expect(response).to render_template :edit
end

Expand Down Expand Up @@ -89,15 +88,14 @@
'price' => 1010101,
'advertiser_id' => 1010101,
'image' => Rack::Test::UploadedFile.new(File.join(Rails.root, 'spec/fixture/image.jpg'))
},
id: @ad.id }
}, id: @ad.id }
expect(response).to redirect_to(ad_index_path)
end
end

context 'when something empty' do
it 'without text should be rendered' do
patch :update, params: { ad: { 'text' =>nil }, id: @ad.id }
patch :update, params: { ad: { 'text' => nil }, id: @ad.id }
expect(response).to render_template :edit
end

Expand All @@ -122,8 +120,7 @@
'price' => nil,
'advertiser_id' => nil,
'image' => nil
},
id: @ad.id }
}, id: @ad.id }
expect(response).to render_template :edit
end
end
Expand Down
8 changes: 4 additions & 4 deletions spec/features/path_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@
end

it 'new valid?' do
click_link('New')
click_link('新規作成')
expect(current_path).to eq new_ad_path
end
end

describe 'Buttons' do
context 'after new ad created' do
before do
visit 'ad/new'
visit new_ad_path
fill_in 'ad_text', with: 'TextForm'
fill_in 'ad_price', with: '1000'
fill_in 'ad_advertiser_id', with: '1'
Expand All @@ -64,11 +64,11 @@

context 'on Index Page' do
it 'edit clickable' do
click_link('Edit')
click_link('変更')
end

it 'Delete clickable and its action workable' do
expect { click_link 'Delete' }.to change { Ad.count }.by(-1)
expect { click_link '削除' }.to change { Ad.count }.by(-1)
end
end
end
Expand Down
6 changes: 0 additions & 6 deletions test/application_system_test_case.rb

This file was deleted.

Empty file removed test/controllers/.keep
Empty file.
40 changes: 0 additions & 40 deletions test/controllers/ad_controller_test.rb

This file was deleted.

Empty file removed test/fixtures/.keep
Empty file.
13 changes: 0 additions & 13 deletions test/fixtures/ads.yml

This file was deleted.

Empty file removed test/fixtures/files/.keep
Empty file.
Empty file removed test/helpers/.keep
Empty file.
Empty file removed test/integration/.keep
Empty file.
Empty file removed test/mailers/.keep
Empty file.
Empty file removed test/models/.keep
Empty file.
8 changes: 0 additions & 8 deletions test/models/ad_test.rb

This file was deleted.

Empty file removed test/system/.keep
Empty file.
11 changes: 0 additions & 11 deletions test/test_helper.rb

This file was deleted.