質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.46%
Ruby

Rubyはプログラミング言語のひとつで、オープンソース、オブジェクト指向のプログラミング開発に対応しています。

Ruby on Rails

Ruby on Railsは、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

JavaScript

JavaScriptは、プログラミング言語のひとつです。ネットスケープコミュニケーションズで開発されました。 開発当初はLiveScriptと呼ばれていましたが、業務提携していたサン・マイクロシステムズが開発したJavaが脚光を浴びていたことから、JavaScriptと改名されました。 動きのあるWebページを作ることを目的に開発されたもので、主要なWebブラウザのほとんどに搭載されています。

Q&A

解決済

1回答

685閲覧

文字のみの投稿がエラーも出ず投稿ビューから遷移せず、投稿ができない。

nao---

総合スコア1

Ruby

Rubyはプログラミング言語のひとつで、オープンソース、オブジェクト指向のプログラミング開発に対応しています。

Ruby on Rails

Ruby on Railsは、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

JavaScript

JavaScriptは、プログラミング言語のひとつです。ネットスケープコミュニケーションズで開発されました。 開発当初はLiveScriptと呼ばれていましたが、業務提携していたサン・マイクロシステムズが開発したJavaが脚光を浴びていたことから、JavaScriptと改名されました。 動きのあるWebページを作ることを目的に開発されたもので、主要なWebブラウザのほとんどに搭載されています。

0グッド

0クリップ

投稿2021/04/04 08:29

いろんな投稿機能を付けています。
その一つに文字のみの投稿の際ハッシュタグ付き機能も付けていました。
その再々色々エラーがでましたが、無事実装することができました。
ただ今は投稿ボタンを押した際に下記のような問題が起きます。
・ハッシュタグ付きで投稿ボタンを押しても、投稿画面から遷移しない(びくともしない)
・ハッシュタグなしで投稿しようとすると長文の際も投稿画面から遷移しない(びくともしない)
(短文ハッシュタグなしだと、たまに投稿ができる)

ただ、URL部分に直接投稿画面のURLを打ってから投稿してみると無事ハッシュタグも投稿することができます。
あと、ターミナルやエラー画面などはなにもエラーコードは出ていません。
なので、投稿が出来ないときはコントーラーにデータが渡っていないと思っています。

下記がコードとなります。

routes.rb Rails.application.routes.draw do get 'rooms/show' # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html devise_for :users resources :rooms get '/search' => 'search#search' root 'home#index' get '/about'=> 'home#about' resources :sounds do resources :comments, only: [:create, :destroy] resources :likes, only: [:create, :destroy] end resources :sentences do resources :comments, only: [:create, :destroy] resources :likes, only: [:create, :destroy] end resources :videos do resources :comments, only: [:create, :destroy] resources :likes, only: [:create, :destroy] end resources :images do resources :comments, only: [:create, :destroy] resources :likes, only: [:create, :destroy] end resources :icons resources :users do get 'images' => 'users#images' get 'videos' => 'users#videos' get 'sounds' => 'users#sounds' get 'sentences' => 'users#sentences' get '/likes' => 'users#likes' get '/following_works' => 'users#following_works' member do get :following, :followers end end resources :relationships, only: [:create, :destroy] end
<!DOCTYPE html> <html> <head> <title>Creators</title> <%= csrf_meta_tags %> <%= csp_meta_tag %> <%= stylesheet_link_tag'application', media: 'all', 'data-turbolinks-track': 'reload' %> <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %> <%# 画像拡大ー始まり%> <link href="https://cdnjs.cloudflare.com/ajax/libs/lightbox2/2.7.1/css/lightbox.css" rel="stylesheet"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/lightbox2/2.7.1/js/lightbox.min.js" type="text/javascript"></script> <%# 画像拡大ー終わり%> <body> <% unless user_signed_in? %> <% else %> <header class="header-3"> <div class="header-inner"> <div class="logo"> <%= link_to root_path do %> Creators <% end %> <div class="tagname"> <%= form_tag(search_path,:method => 'get') do %> <%= text_field_tag :tagname, value= nil, placeholder: "#タグで検索" %> <% end %> </div> </div> <nav class="header-nav"> <div class="header-nav-item"> <div class="header-button header-login"> </div> </div> <div class="header-button"> <%= link_to videos_path do %> <%= image_tag 'movie.png', :size=> "40x40" %> <% end %> </div> <div class="header-button"> <%= link_to sounds_path do %> <%= image_tag 'sound.png', :size=> "40x40" %> <% end %> </div> <div class="header-button"> <%= link_to sentences_path do %> <%= image_tag 'pen.png', :size=> "50x50" %> <% end %> </div> <div class="header-button"> <% if current_user %> <%= link_to user_path(current_user.id) do %> <%= image_tag 'portfolio.png', :size=> "35x35" %> <% end %> <% end %> </div> <div class="header-button"> <%= link_to rooms_path do %> <%= image_tag 'chat3.png', :size=> "45x45" %> <% end %> </div> <%= link_to user_following_works_path(current_user.id) do %> <div class="header-button header-post" > FollowingWorks </div> <% end %> <div class="header-nav-item"> <div class="header-button header-post" id="openModal">Create!</div> </div> <div id="modalArea" class="modalArea"> <div id="modalBg" class="modalBg"></div> <div class="modalWrapper"> <div class="modalContents"> <%= render 'layouts/posts_form' %> </div> <div id="closeModal" class="closeModal"> × </div> </div> </div> <div class="header-button"> <% if user_signed_in? %> <% @icon = Icon.find_by(user_id: current_user.id)%> <% if @icon %> <%= image_tag @icon.icon, :size => '30', class: 'usericon' %> <% else %> <%= image_tag 'user.png', :size => '30', class: 'usericon' %> <% end %> <div class="usercontent"> <ul> <li> <%= link_to user_path(current_user.id) do %> <%= image_tag 'user.png', :size => '20' %> プロフィール <% end %> </li> <li> <%= link_to following_user_path(current_user.id) do %> <%= image_tag 'users2.png', :size => '20' %> フォロワー <% end %> </li> <li> <%= link_to user_likes_path(current_user.id) do %> <%= image_tag 'like.png', :size => '20' %> いいね <% end %> </li> <li> <%= link_to 'about', about_path %> </li> <li> <% if user_signed_in?%> <%= link_to 'ログアウト', "/users/sign_out", method: :delete %> <% else %> <a href="/users/sign_up">sign-up</a> <a href="/users/sign_in">sign-in</a> <% end %> </li> </ul> <% end %> </div> </div> <div class="header-username"> <% if current_user %> <%= link_to user_path(current_user.id) do %> <%= current_user.nickname %> <% end %> </div> <% end %> </nav> </div> </header> <% end %> <%= yield %> </body> </html>
<div class="posts-wrapper"> <div class="image-post" id="postsIcons"> <%= link_to image_tag('brush.png', :size => '90' ), new_image_path %> <p id="image-post-text">画像</p> </div> <div class="sound-post" id="postsIcons"> <%= link_to image_tag('sound.png', :size => '90' ), new_sound_path %> <p id="sound-post-text">音楽</p> </div> <div class="text-post" id="postsIcons"> <%= link_to image_tag('note.png', :size => '90' ), new_sentence_path %> <p id="text-post-text">文字</p> </div> <div class="video-post" id="postsIcons"> <%= link_to image_tag('video.png', :size => '90' ), new_video_path %> <p id="video-post-text">動画</p> </div> </div>
class SentencesController < ApplicationController before_action :move_to_index, except: [:index, :show] def index @sentence = Sentence.includes(:user).order("created_at DESC") end def new @sentence = Sentence.new end def create @sentence = Sentence.new(sentence_params) if @sentence.user_id = current_user.id @sentence.save redirect_to action: :index end end def destroy sentence = Sentence.find(params[:id]) if sentence.user_id == current_user.id sentence.destroy end end def edit @sentences = Sentence.find(params[:id]) if @sentences.user_id != current_user.id redirect_to "/sentences" end end def update sentence = Sentence.find(params[:id]) if sentence.user_id == current_user.id sentence.update(sentence_params) end end def show @sentences = Sentence.find(params[:id]) @comment = Comment.new @comments = @sentences.comments.order(created_at: :desc) @com = "sentence" @like = Like.new end private def sentence_params params.require(:sentence).permit(:title, :summary, :content, :tag_ids) end def move_to_index redirect_to action: :index unless user_signed_in? end end
class Sentence < ApplicationRecord belongs_to :user has_many :comments has_many :likes, dependent: :destroy has_many :likes_users, through: :likes, source: :user has_many :post_tags, dependent: :destroy has_many :tags, through: :post_tags after_create do sentence = Sentence.find_by(id: self.id) tags = self.summary.scan(/[##][\w\p{Han}ぁ-ヶヲ-゚ー]+/) tags.uniq.map do |t| tag = Tag.find_or_create_by(name: t.downcase.delete('#')) sentence.tags << tag end end end
投稿画面 <div class="posts-wrapper-content">  <div class="preview" id="image"> <%= form_with model: @sentence, local: true do |s| %> <div class="sentence-content"> <%= s.text_area :content, placefolder: "story" %> </div> </div> <div class="information-content"> <div class="info-cover"> <div class="title-form"> :タイトルを入力してください </div> <%= s.text_field :title %> <div class="content-wrapper"> :内容を入力してください。 </div> <%= s.text_area :summary, class: 'content-form' %> <%= s.submit "投稿する", class: 'send-button' %> </div> <% end %> </div> </div>

バージョン
ruby 2.6.6
rails 5.2.4.5

他、画像投稿の際もハッシュタグ機能を付けているのですが
その際は、何も問題なく動きます。
なので、とても混乱していてどこが悪いのかはっきり分かってない状態になります。
ご教授いただきたいです。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

nao---

2021/04/04 11:43

↳ app/controllers/sentences_controller.rb:56 Rendering sentences/new.html.erb within layouts/application Rendered sentences/new.html.erb within layouts/application (2.3ms) Rendered layouts/_posts_form.html.erb (4.4ms) Icon Load (0.4ms) SELECT `icons`.* FROM `icons` WHERE `icons`.`user_id` = 1 LIMIT 1 ↳ app/views/layouts/application.html.erb:93 ActiveStorage::Attachment Load (0.5ms) SELECT `active_storage_attachments`.* FROM `active_storage_attachments` WHERE `active_storage_attachments`.`record_id` = 1 AND `active_storage_attachments`.`record_type` = 'Icon' AND `active_storage_attachments`.`name` = 'icon' LIMIT 1 ↳ app/views/layouts/application.html.erb:96 ActiveStorage::Blob Load (0.6ms) SELECT `active_storage_blobs`.* FROM `active_storage_blobs` WHERE `active_storage_blobs`.`id` = 2 LIMIT 1 ↳ app/views/layouts/application.html.erb:96 Completed 200 OK in 179ms (Views: 172.3ms | ActiveRecord: 2.9ms) このようなコードのことですよね? それが、送信ボタンを押してもびくともせずターミナルにも何も表示されてない状況となっています。
guest

回答1

0

自己解決

自己解決できました。

なぜかform_withの位置を一番上にしてhtmlのdivタグを挟むようにすると
すんなり投稿できました。理由は正直完璧には分かっていませんが
これを参考にしました。
https://teratail.com/questions/237566?whotofollow=

投稿2021/04/04 15:05

nao---

総合スコア1

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.46%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問