1

さて、何時間もレールのファイルフィールドをスタイルする方法を見つけようとしてきましたが、何も見つかりませんでした。css と js を使用してファイル フィールドのスタイルを設定したいのですが、これまでレールでスタイルを設定できません。これまでに持っているものを以下にリストしました。

  <div class="field uploader blue">
    <%= f.text_field :photo, class: "filename", readonly: "readonly" %>
    <%= f.file_field :photo %>
  </div>

Javascript

jQuery("input[type=file]").change(function(){$(this).parents(".uploader").find(".filename").val(jQuery(this).val());});
jQuery("input[type=file]").each(function(){
    if(jQuery(this).val()==""){jQuery(this).parents(".uploader").find(".filename").val("No file selected...");}
});

レールではなくhtmlを使用して動作します

<div class="uploader blue">
  <input type="text" class="filename" readonly="readonly"/>
  <input type="button" name="file" class="button" value="Browse..."/>
  <input type="file" size="30"/>
</div>

Railsのファイルフィールドのヘルパーや、ヘルパーを使用してアップロードと入力ボタンを分割して、HTMLコードと同じようにコードを取得できる方法はありますか?

4

0 に答える 0