現在私は、twitterのような投稿サイトを作ろうと考えています。そのため、投稿しようと考えているのですが、なぜか投稿を保存することができない状態になっています。他のテーブルはスームズにできたのですが、今回のだけうまくいかない状態になっています。
controller
1class PickupsController < ApplicationController 2 3 def index 4 5 end 6 7 def show 8 end 9 10 def new 11 end 12 13 def edit 14 @pickups = pickup.find(params[:id]) 15 @groups = current_user.groups.group(:group_name).page(params[:page]).per(1).order("created_at DESC") 16 17 end 18 19 def update 20 end 21 22 def create 23 Pickup.create(content: params[:content], detail: params[:detail], image: params[:image], date: params[:date], hash_tag: params[:hash_tag], 24 university: params[:university], region: params[:region], group_id: params[:group_id], user_id: current_user.id) 25 26 end 27 28 private 29 def pickup_params 30 params.permit(:content, :detail, :image, :date, :hash_tag, :university, :region, :group_id) 31 end 32 33end 34
model
1validates :pickup, length: { minumum: 10, maximum: 250 } 2 belongs_to :group 3 belongs_to :user 4 has_many :likes 5 has_many :likes, foreign_key: :pickup_id, dependent: :destroy 6 has_many :liked_users, through: :likes, source: :user 7 has_many :notifications, dependent: :destroy 8 9 def create_notification_by(current_user) 10 notification = current_user.active_notifications.new( 11 pickup_id: id, 12 visited_id: user_id, 13 action: "like" 14 ) 15 notification.save if notification.valid? 16 end 17 18 19 20 mount_uploader :image, ImageUploader
view
1<div class="sp" style="overflow-x: visible;"> 2 <%= form_tag("/pickups", method: :post) do %> 3 <div style="height: 35px; margin-top: 10px; margin-left: 20px; width: 100vw; position: relative;"> 4 <div style="width: 65%; display: inline-block;"> 5 <a href="/" style=""><span style="color: #ffba44; display: inline-block; margin-top: 0; position: absolute; top:3px;"><i class="fas fa-arrow-left" style="font-size: 18px;"></i></span></a> 6 </div> 7 <div style="width: 30%; display: inline-block; text-align: center;"> 8 <input type="submit" value="ツナガル" style="background-color: #ffba44; border: #ffba44; color: #fff; border-radius: 20px; padding: 5px 10px; font-size: 11px; font-weight: bold; position: absolute; left: 72%; top:0px;"> 9 </div> 10 </div> 11 <div class="dbar"></div> 12 13 <div style="height: 250px;"> 14 15 <div style="width: 100vw; height: 100px; display: flex;"> 16 <div style="width: 15%; height: 200px;; margin-left: 10px; margin-top: 10px; display: flex;"> 17 <img src="/images/new-wa1.png" style="width: 49px; height: 49px;"> 18 </div> 19 <div style="width: 80%; height: 200px; display: flex; margin-top: 10px;"> 20 <textarea type="text" name="detail" style="border: #fff; width: 100%; height: auto; user-select: text; -webkit-user-modify: read-write-plaintext-only;" autofocus></textarea> 21 </div> 22 </div> 23 </div> 24 25 <div style="width: 100vw; height: 100px; display: flex; margin: 0 40px;"> 26 <div style="width: 15%; height: 40px;; margin-left: 10px; margin-top: 10px; display: flex; font-size: 30px;"> 27 <i class="far fa-image" style="border: 1px solid #e3e4e8; padding: 10px 10px; height: 30px; border-radius: 5px;"></i> 28 </div> 29 <div class="sl" style="width: 180px; height: 28px; display: flex; margin-top: 10px; position: relative; background: #ffffff; color: orange; border: 1px solid orange;"> 30 31 <%= file_field_tag 'image', class: "image", style: "display:none;",id: "file5" %> 32 <div id="img_field5" onClick="$('#file5').click()" class="igg" style="border: 2px dotted #e3e4e8; border-radius: 4px; height: 20px; padding: 10px; border: unset; margin: 0;"> 33 <p class="upds" style="position: absolute; margin-top: 6px; cursor: pointer; top: 0; left: 0; margin-left: 7%; margin-top: 8%;">画像をアップロードする</p> 34 </div> 35 36 </div> 37 </div> 38 39 </div> 40 41 42 <% end %> 43 44 </div> 45 </div>
db
1class CreatePickups < ActiveRecord::Migration 2 def change 3 create_table :pickups do |t| 4 t.text :detail 5 t.string :content 6 t.text :image 7 t.text :date 8 t.string :hash_tag 9 t.string :university 10 t.string :region 11 t.integer :user_id 12 t.integer :group_id 13 14 t.timestamps null: false 15 end 16 end 17end 18
route
1resources :pickups
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2020/07/18 08:22