ログイン
ユーザ名:

パスワード:


パスワード紛失

新規登録
メインメニュー
検索
オンライン状況
18 人のユーザが現在オンラインです。 (1 人のユーザが ニュース を参照しています。)

登録ユーザ: 0
ゲスト: 18

もっと...
投稿者: f-otake 投稿日時: 2015-11-15 9:21:52 (1741 ヒット)

rails version 4.xx
モデルには librarie と doc があり、それぞれ(抜粋)

class Library < ActiveRecord::Base
accepts_nested_attributes_for :docs, allow_destroy: true
class Doc < ActiveRecord::Base
belongs_to :library
となっています。
この時、libraries_controllers.rbのeditはdefaultのままで、edit.html.erbから飛ぶ_form.html.erb(抜粋)
<%= nested_form_for @library, :html => { :class => "form-horizontal library" } do |f| %><font color=#006400 ->
 ---------- 省略
    <table class="table table-striped">
      <thead>
        <tr>
          <th><%= model_class.human_attribute_name(:ファイル名  **編集の場合ファイル名とバージョンは変更不可**) %></th>
          <th><%= model_class.human_attribute_name(:バージョン) %></th>
          <th><%= model_class.human_attribute_name(:備考) %></th>
        </tr>
      </thead>
      <%= f.fields_for :docs do |df| %>
      <tr class="nested-fields">
        <td><%= f.text_field :file_name, :readonly => true, :size => 56 %></td>
        <td><%= f.text_field :version, :readonly => true, :size => 8 %></td>
        <td><%= f.text_area :remarks, :size => "30x1" %></td>
      </tr>
      <% end %>  
      <td></td><td><%= f.submit '保存', class: 'btn btn-primary' %></td>
    </table>
<% end %>
となっています。この状態でupdateすると、
データーベースに2重に登録され、もちろんshowにも二つづつ表示され、さらに悪いことに片方を削除するとデーターベースはつじつまが合うのですが、ここには記入してありませんが、Doc(色々なファイル)をWEBに保存してあり、それが削除され、残っているDocをクリックしてもファイルが無いのでエラーになります
あちゃちゃ、これは大変だー。何でだ!!........ そうかIDが無いので二重に登録されるのか、だったらIDも渡せばいいのだー。これは簡単、libraries_controllers.rbのストロング・パラメーターに登録しよう。
class LibrariesController < ApplicationController
  ---------- 省略
  private
    # Use callbacks to share common setup or constraints between actions.
    def set_library
      @library = Library.find(params[:id])
    end

    # Never trust parameters from the scary internet, only allow the white list through.
    def library_params
      params.require(:library).permit(:prod, :model, :serial_no, :seizo_nen, :company, :branch, :section,
       :incharge, :nonyu_bi, :remarks, :pictures,
             :docs_attributes => [:id, :file_name, :version, :remarks, :_destroy],
             :pictures_attributes => [:images, :_destroy]) ←これは他のモデルの分
    end
end
これでめでたし、めでたし
だけど、セキュリティー的にはどうなのかなー?IDを受け付けると言うことは改竄の危険があるのかな??詳しい方教えて下さい。お問い合わせから連絡出来ます。


投稿者: f-otake 投稿日時: 2015-5-23 9:23:18 (3663 ヒット)

Gemfileに gem 'jquery-ui-rails'と記入し、app/asset/javascripts/application.jsに //= require jquery.ui.all、 app/asset/stylesheets/application.cssの最後の*/の前に *= require jquery.ui.all をそれぞれ追記し、サーバーを ctrl+c で止め、再度 rails s でスタートさせると
couldn't find file 'jquery.ui.all' with type 'text/css' とエラーが出た。
jquery-ui-rails の記入の仕方が 5.0 から変わった見たい。ここに回答があった
application.jsには //= require jquery-ui、application.cssには *= require jquery-ui と記入後、再度サーバーを立ち上げ直すとOKになった。


テーマ選択

(4 テーマ)
ミニカレンダー
前月2024年 3月翌月
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31
<今日>
ピックアップ画像
2008_11_14 15:16:19
最近の画像
IMG_0004.jpg (2023-3-17)
IMG_0004.jpg
IMG_0003.jpg (2023-3-17)
IMG_0003.jpg
IMG_0010.jpg (2023-3-17)
IMG_0010.jpg
IMG_0013.jpg (2023-3-17)
IMG_0013.jpg
IMG_0007.jpg (2023-3-17)
IMG_0007.jpg
IMG_0005.jpg (2023-3-17)
IMG_0005.jpg
IMG_0002.jpg (2023-3-17)
IMG_0002.jpg
IMG_0011.jpg (2023-3-17)
IMG_0011.jpg
IMG_0009.jpg (2023-3-17)
IMG_0009.jpg
IMG_0008.jpg (2023-3-17)
IMG_0008.jpg
人気画像
ゴーキョピー... (5991 hits)
ゴーキョピー...
ギャチュンカ... (5851 hits)
ギャチュンカ...
ばあちゃんミ... (5750 hits)
ばあちゃんミ...
ヒマラヤ壁 (5658 hits)
ヒマラヤ壁
タムセルク残... (5467 hits)
タムセルク残...
Powered by Xoops2 Theme Modified by F-Otake
copyright (c) 2006 All rights reserved.