rails初学者で初めてオリジナルアプリを作っているのですが、投稿画面でスムーズに投稿できずそれについてのエラ〜メッセージなどもなくなにが原因でどう解消すればいいか分からず困っています
発生している問題・エラーメッセージ
投稿画面で、文字や数字などを入力し投稿ボタンを押しても投稿できないという問題が起こっているのですが、リロードすれば解消され、エラ〜メッセージなどはなにも出ていません
リロードせずに初めから投稿ちゃんと投稿できる状態にしたいのですがエラ〜メッセージなどはなくなにがおかしくてこのようなことが起きているのか全く分からない状態です(リロードする前の画面では投稿ボタンを押してもlogには記録が残りません)
該当のソースコード
**contorollers - posts_contoroller** class PostsController < ApplicationController before_action :authenticate_user before_action :ensure_correct_user,{only:[:edit,:update,:destroy]} def index @post = Post.all.order(created_at: :desc) end def show @post = Post.find_by(id: params[:id]) end def new @post = Post.new end def create @post = Post.new( content: params[:content], type: params[:type], time: params[:time], user_id: @current_user.id ) if @post.save redirect_to("/users/#{@current_user.id}") else render("posts/new") end end def edit @post = Post.find_by(id: params[:id]) end def update @post = Post.find_by(id: params[:id]) @post.content = params[:content] @post.content = params.permit(:content)[:content] @post.time = params.permit(:time)[:time] @post.type = params.permit(:type)[:type] if @post.save redirect_to("/users/#{@current_user.id}") else render("posts/edit") end end def destroy @post = Post.find_by(id: params[:id]) @post.destroy redirect_to("/users/#{@current_user.id}") end def ensure_correct_user @post = Post.find_by(id: params[:id]) if @post.user_id != @current_user.id flash[:notice]= "権限がありません" redirect_to("/posts/index") end end end
**posts - new.html.erb** <div class="edit-wrapper"> <div class="cont"> <div class="edit-wrapper-main"> <div class="edit-title"> <h1>今日の積み上げ</h1> </div> <div class="edit-contents"> <div class="edit-content edit-1"> <p>今日の積み上げ時間</p> <%= form_tag("/posts/create") do %> <p><textarea class="edit-time" type="text" name="time" value=""> </textarea>分</P> </div> <div class="edit-content edit-2"> <p>今日やったこと</p> <textarea class="edit-thing" type="text" name="type" value=""> </textarea> </div> <div class="edit-content"> <p>具体的な内容</p> <textarea name="content" rows="8" cols="80"> </textarea> </div> <input class="edit-submit" type="submit" name="" value="投稿"> <% end %> </div> </div> </div> </div>
**migrate - add_time_to_post.rb** class AddTimeToPosts < ActiveRecord::Migration[5.2] def change add_column :posts, :time, :integer end end
**create_posts.rb** class CreatePosts < ActiveRecord::Migration[5.2] def change create_table :posts do |t| t.text :content t.timestamps end end end
**migrate - add_type_to_post.rb** class AddTypeToPosts < ActiveRecord::Migration[5.2] def change add_column :posts, :type, :string end end
ぼく自身、なにが原因か皆目検討もつかないという状況ですので貼るコードがこれらで正しいのか?(不足はないか)というのが分からないですので、ここにあるもの以外でみたいコードなどがありましたらコメント欄にお願いします
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。