質問するログイン新規登録

質問編集履歴

3

ソスコードにmigrate file追記

2016/04/02 07:21

投稿

Takoyakis
Takoyakis

スコア16

title CHANGED
File without changes
body CHANGED
@@ -28,7 +28,7 @@
28
28
  before_action :authenticate_user!, only: :new
29
29
 
30
30
  def create
31
- @posting = Posting.new(category_id: posting_params[:category_id], name: posting_params[:name], gram: posting_params[:gram], temperature: posting_params[:temperature], time: posting_params[:time], experience: posting_params[:experience], coment: posting_params[:coment], user_id: current_user.id, image: posting_params[:image])
31
+ @posting = Posting.new(user_id: current_user.id, image: posting_params[:image])
32
32
 
33
33
  if @posting.save
34
34
  render :file => "/postings/create.html.erb"
@@ -37,7 +37,13 @@
37
37
  end
38
38
  end
39
39
 
40
+ private
41
+ def posting_params
42
+ params.permit(:user_id, :image)
43
+ end
44
+ end
40
45
 
46
+
41
47
  model
42
48
 
43
49
  class Posting < ActiveRecord::Base
@@ -53,6 +59,22 @@
53
59
  end
54
60
 
55
61
 
62
+ migrate file
63
+
64
+ class AddAttachmentImageToPostings < ActiveRecord::Migration
65
+ def self.up
66
+ change_table :postings do |t|
67
+ t.attachment :image
68
+ end
69
+ end
70
+
71
+ def self.down
72
+ remove_attachment :postings, :image
73
+ end
74
+ end
75
+
76
+
77
+
56
78
  view
57
79
  <p>写真</p>
58
80
  <div class="posting_form">

2

 

2016/04/02 07:21

投稿

Takoyakis
Takoyakis

スコア16

title CHANGED
File without changes
body CHANGED
File without changes

1

 

2016/04/02 04:13

投稿

Takoyakis
Takoyakis

スコア16

title CHANGED
@@ -1,1 +1,1 @@
1
- 初心者です。Railsで 投稿した画像がDBに保存できません
1
+ Railsです。paperclipを使っても投稿した画像がDBに保存できません(涙)
body CHANGED
File without changes