たれみみマンデー

Rails5のチャットでハマったとこ。jQueryの読み込みエラー

Rails5でチャット実装をしようと色々なサイトを見ていたのですが、動かず初歩的なミス。coffeeで$とか入ってるのにjQueryを読み込んでなかった。

って事で入れる。

gem 'jquery-rails'

gem 'jquery-ui-rails'

そしたらさらに

couldn't find file 'jquery-ujs' with type 'application/javascript'

ってでました。

以下の記述で動きました。(順序でハマりました)

 

app/assets/javascripts/application.js

//= require jquery

//= require jquery-ui/widgets/datepicker

//= require rails-ujs

//= require turbolinks

//= require_tree .

 (補足)

( もしrequireでbootstrap系を書く場合は、必ずjQuery読み込みの後に記述すべきとのことです!BoostrapはjQueryが必須なので。)

 

app/assets/stylesheets/application.css

*= require jquery-ui/datepicker

*= require_tree .

*= require_self

 */

 

どなたかの参考になれば幸いです。

 

 

https://github.com/jquery-ui-rails/jquery-ui-rails#require-specific-modules

 

コントローラー内のrender actionでエラー【Ruby on Rails】

 

Render and/or redirect were called multiple times in this action. Please note that you may only call render OR redirec

ってエラーでた。

場所はcontrollerの中のrender action :*****

 

【Rails】コントローラの中で途中で抜ける方法 - 東京伊勢海老通信

 

解決した。

render action: :****  and return

 

最後にこう書けば良いみたい。

うまいことコントローラー抜けれるっぽい。

モデルのモデルのモデルをネストして画像も同時にフォームで保存

ポイントはfields_forとobjectで画像にアクセス。

プレビュー出すのアクセスかなりハマった。

<div class="image-upload-container">
     <%= f.fields_for :thumbnails do |t| %>
        <div class="image-upload-box">
    
        <%= t.file_field :image, class: "btn-upload" %>
        <% if  t.object.image.url.present? && n>=3 %>
         <%= t.check_box :_destroy , class: "check-destroy" %>
          <%= t.label :_destroy , class: "btn-destroy" do %>
          <% end %>
        <% end %>
   
        <%= t.label :image, class: "btn-upload-label" do %>
   
          <% if t.object.image.url.present? %>                                                         
            <%= image_tag t.object.image.url, class:"uploaded-image" %>
          <% end %>
          <span class="label-plus">+</span>
          <span class="label-text">画像未選択</span>
   
        <% end %>
   
        <% n+=1 %>
      </div>
    <% end %>
  </div>

 

自分用ビボウロク。

Railsでスマホから画像をアップしたときに画像が回転する問題

Carriwave等々でRailsスマホから画像をアップすると時々横向きに回転するのでその対策法。

app/uploaders/image_uploader.rb   

   process :fix_exif_rotation                                                                                                           
     def fix_exif_rotation
        manipulate! do |img|
        img.auto_orient!
        img = yield(img) if block_given?
        img 
        end 
      end

 

英語でもなかなか出てこなかったので

だれかのためになれば幸いです。