2017-02-10 30 views
1

私はチェックボックス、trixエディタ、ラジオボタン、およびテキストフィールドを持つフォームを持っています。管理インターフェースでレコードを編集すると、フォームにすべてのテキストフィールドが表示されます。 trixエディタ、チェックボックス、ラジオボタンを見ることができません。フォームのチェックボックス、ラジオとtrixエディタがActiveAdminにあらかじめ入力されていない

私はas: :radioas: :check_boxesas: :trix_editorが動作するはずです知っているが、彼らはここですでに保存された値

移入前は私のjobposting.rbファイルで取得されていません。

本当にありがとうございます。

form do |f| 
    f.inputs "New Job Posting" do 
     f.input :title 
     f.input :description, as: :trix_editor 
     f.input :how_to_apply, as: :trix_editor 
     f.input :job_type, as: :radio 
     f.input :city 
     f.input :user_id 
     f.input :categories, as: :check_boxes 

     f.input :publish 


    end 
    f.actions 
    end 

とフォームがそのがトリックスエディタを持っているはずである(を適用する方法、説明を)フィールドが表示されないこの

enter image description here

のように表示されます。ラジオ用(ジョブタイプ)とボックス(カテゴリー)をチェックし、これらのフィールドの実際の値は、これらのenter image description here

EDITED

Started GET "/admin/job_postings/3/edit" for ::1 at 2017-02-11 12:41:22 +0530 
Processing by Admin::JobPostingsController#edit as HTML 
    Parameters: {"id"=>"3"} 
    AdminUser Load (0.4ms) SELECT "admin_users".* FROM "admin_users" WHERE "admin_users"."id" = $1 ORDER BY "admin_users"."id" ASC LIMIT 1 [["id", 1]] 
    JobPosting Load (0.3ms) SELECT "job_postings".* FROM "job_postings" WHERE "job_postings"."id" = $1 LIMIT 1 [["id", 3]] 
    CACHE (0.0ms) SELECT "job_postings".* FROM "job_postings" WHERE "job_postings"."id" = $1 LIMIT 1 [["id", "3"]] 
    Rendered /Users/KrishnaTeja/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/bundler/gems/activeadmin-2bb5021f81c2/app/views/active_admin/resource/edit.html.arb (270.1ms) 
Completed 500 Internal Server Error in 367ms (ActiveRecord: 7.4ms) 

ActionView::Template::Error (undefined method `categories' for #<Class:0x007ffdd084e420>): 
    1: insert_tag renderer_for(:edit) 
    app/admin/job_postings.rb:26:in `block (3 levels) in <top (required)>' 
    app/admin/job_postings.rb:18:in `block (2 levels) in <top (required)>' 


    Rendered /Users/KrishnaTeja/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/actionpack-4.2.7.1/lib/action_dispatch/middleware/templates/rescues/_source.erb (16.6ms) 
    Rendered /Users/KrishnaTeja/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/actionpack-4.2.7.1/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (7.9ms) 
    Rendered /Users/KrishnaTeja/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/actionpack-4.2.7.1/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb (1.8ms) 
    Rendered /Users/KrishnaTeja/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/actionpack-4.2.7.1/lib/action_dispatch/middleware/templates/rescues/template_error.html.erb within rescues/layout (115.2ms) 

ているように、その表示するシンプルなはいとno..whereをフィールドenter image description hereenter image description here

あなたがcategorieをチェックする場合、これは私のviews/job_postings/_form.html.erb ですどのテーブルからも来ていないフィールドは配列を持ち、それを反復しています。

<%= form_for @job_posting do |f| %> 
<% if @job_posting.errors.any? %> 
     <div id="errors"> 
      <h2><%= pluralize(@job_posting.errors.count, "error") %> prevented this post from saving:</h2> 
      <ul> 
       <% @job_posting.errors.full_messages.each do |msg| %> 
        <li><%= msg %></li> 
       <% end %> 
      </ul> 
     </div> 
    <% end %> 

<p> 
    <%= f.label :title %> 
    <%= f.text_field :title %> 
</p> 

<p> 
    <%= f.label :description %> 

    <%= f.trix_editor :description %> 

</p> 
<p> 
    <%= f.label :how_to_apply %> 
    <%= f.trix_editor :how_to_apply %> 
</p> 
<p> 
    <%= f.label :categories %> 

    <% [ 'Front End', 'Back End', 'Others'].each do |category| %> 
     <%= label_tag "job_posting_categories_#{category}", category %> 

     <%= check_box_tag "job_posting[categories][]", category, checked(category), id: "job_posting_categories_#{category}" %> 


    <% end %> 

</p> 
<p> 
    <%= f.label :job_type %> 
    <% [ 'FullTime', 'Contract', 'PartTime', 'Freelance', 'Intern'].each do |job_type| %> 
     <%= f.radio_button 'job_type', job_type %> 
      <%= job_type.humanize %> 
    <% end %> 

</p> 
<p> 
    <%= f.label :city %> 
    <%= f.text_field :city %> 
</p> 
    <%= f.submit "Post Job" %> 


<% end %> 
+0

を解決しましたxes'と 'radio'などがあります。あなたが今投稿したように、レンダリングされているものは完全に動作しているからです。私たちはあなたが望むようにコードを見る必要があり、その結果のスクリーンショット – LBarry

+0

@LBarry私はさらに情報を追加しました。正確ではないと申し訳ありません。 –

+0

@KrishnaTejaKarnam:答えはここの回答ボックスに表示されます。自己解答にコピーして、ソリューションに追加する前に質問を最新の状態に戻しますか?ありがとうございました。 – halfer

答えて

1

あなたは `check_boでコードを投稿してくださいでした

ActiveAdmin.register JobPosting do 

# See permitted parameters documentation: 
# https://github.com/activeadmin/activeadmin/blob/master/docs/2-resource-customization.md#setting-up-strong-parameters 
# 
permit_params :title, :description,:how_to_apply, :job_type ,:city,:user_id,{ categories: []}, :publish 
# 
# or 
# 
# permit_params do 
# permitted = [:permitted, :attributes] 
# permitted << :other if params[:action] == 'create' && current_user.admin? 
# permitted 
# end 


form do |f| 
    inputs "New Job Posting" do 

     input :title 
     input :description 
     input :how_to_apply 
     input :job_type, as: :radio, collection: [ 'FullTime', 'Contract', 'PartTime', 'Freelance', 'Intern'] 
     input :city 
     input :user, member_label: :email 
     input :categories, as: :check_boxes, collection: ['Front End','Back End','Others'].map { |e| [e, e,{checked: f.object.categories.include?(e)}] } 

     input :publish 


    end 
    actions 
    end 


end 
0

trix_editorがactiveadminと互換性がありませんので、私はあなたがすべてでそれを使用することができますかはわからないように思われます。他のものについては、それを表示するコレクションを含める必要があります。そうでない場合は、デフォルトのyes/noボックスが表示されます。したがって、このような何か:

f.input :categories, as: :check_boxes, collection: f.object.categories 

、アクティブな管理はあなたがチェックボックスを移入するカテゴリに利用可能なオプションを使用することを知らせなければなりません。

EDITED:

は、代わりにこれを試してみてください:

form do |f| 
    inputs "New Job Posting" do 
     input :title 
     input :description 
     input :how_to_apply 
     input :job_type, as: :radio 
     input :city 
     input :user_id 
     input :categories, as: :check_boxes, collection: f.object.categories 
     input :publish 
    end 
    actions 
    end 

かさえ:

form do |f| 
    inputs "New Job Posting" do 
     input :title 
     input :description 
     input :how_to_apply 
     input :job_type, as: :radio 
     input :city 
     input :user_id 
     input :categories, as: :check_boxes, collection: JobPosting.categories 
     input :publish 
    end 
    actions 
    end 
+0

私はこの 'f.input:categories 'を::check_boxes、collection:f.object.categories'と追加しました。このエラーは' '未定義のメソッド'" "フロントエンド\"、\ "バックエンド\ "]":String "は型キャストに関連するもののように見えます。私はその愚かなことが行方不明であるかどうかは分かりません。 –

+0

おそらくコレクションから 'f'を削除する必要があるでしょうから、代わりに' collection:object.categories'を使用してください。 – LBarry

+0

それでも同じエラーを受け取っています ''未定義のメソッド "map" for "[\"フロントエンド\ "Back End \"] ":String' –

関連する問題