Я использую этот драгоценный камень для таблиц данных в рельсах, и у меня возникают проблемы при работе с одной моделью, связанной дважды
https://github.com/jbox-web/ajax-datatables-rails
это моя модель
class Associate < ActiveRecord::Base
has_many :missions
has_many :coordinator_missions, :class_name => "Mission", :foreign_key => "coordinator_id"
end
class Mission < ActiveRecord::Base
belongs_to :associate
belongs_to :coordinator, :class_name => "Associate"
end
Показ данных в таблице работает нормально, но я не могу искать из-за координатора
это мой код с датой
class MissionDatatable < AjaxDatatablesRails::Base
def view_columns
@view_columns ||= {
id: { source: "Mission.id", cond: :eq },
fy: {source: "Mission.fy"},
associate_email: {source: "Associate.email"},
associate_id: {source: "Mission.associate_id"},
coordinator_email: { source: "Coordinator.email" },
coordinator_id: { source: "Mission.coordinator_id" },
name: { source: "Mission.name" },
fye_output: { source: "Mission.fye_output" },
status: { source: "Mission.status" },
created_at: { source: "Mission.created_at" },
updated_at: { source: "Mission.updated_at" }
}
end
def data
records.map do |mission|
{
# example:
id: mission.id,
fy: mission.fy,
associate_email: mission.associate.email,
associate_id: mission.associate_id,
coordinator_email: mission.coordinator.email,
coordinator_id: mission.coordinator_id,
name: mission.name,
fye_output: mission.fye_output,
status: mission.status,
created_at: mission.created_at,
updated_at: mission.updated_at
}
end
end
private
def get_raw_records
Mission.joins(:associate).joins(:coordinator)
end
end
Не могли бы вы помочь мне, как сделать правильную настройку для одной модели, связанной дважды?
Ошибка в журнале "неверное имя константы"
редактировать: добавлен журнал
> Started GET
> "/missions.json?draw=3&columns%5B0%5D%5Bdata%5D=fy&columns%5B0%5D%5Bname%5D=&columns%5B0%5D%5Bsearchable%5D=true&columns%5B0%5D%5Borderable%5D=true&columns%5B0%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B0%5D%5Bsearch%5D%5Bregex%5D=false&columns%5B1%5D%5Bdata%5D=associate_email&columns%5B1%5D%5Bname%5D=&columns%5B1%5D%5Bsearchable%5D=true&columns%5B1%5D%5Borderable%5D=true&columns%5B1%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B1%5D%5Bsearch%5D%5Bregex%5D=false&columns%5B2%5D%5Bdata%5D=guild_name&columns%5B2%5D%5Bname%5D=&columns%5B2%5D%5Bsearchable%5D=true&columns%5B2%5D%5Borderable%5D=true&columns%5B2%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B2%5D%5Bsearch%5D%5Bregex%5D=false&columns%5B3%5D%5Bdata%5D=coordinator_email&columns%5B3%5D%5Bname%5D=&columns%5B3%5D%5Bsearchable%5D=true&columns%5B3%5D%5Borderable%5D=true&columns%5B3%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B3%5D%5Bsearch%5D%5Bregex%5D=false&columns%5B4%5D%5Bdata%5D=name&columns%5B4%5D%5Bname%5D=&columns%5B4%5D%5Bsearchable%5D=true&columns%5B4%5D%5Borderable%5D=true&columns%5B4%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B4%5D%5Bsearch%5D%5Bregex%5D=false&columns%5B5%5D%5Bdata%5D=eighty&columns%5B5%5D%5Bname%5D=&columns%5B5%5D%5Bsearchable%5D=true&columns%5B5%5D%5Borderable%5D=true&columns%5B5%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B5%5D%5Bsearch%5D%5Bregex%5D=false&columns%5B6%5D%5Bdata%5D=q1_output&columns%5B6%5D%5Bname%5D=&columns%5B6%5D%5Bsearchable%5D=true&columns%5B6%5D%5Borderable%5D=true&columns%5B6%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B6%5D%5Bsearch%5D%5Bregex%5D=false&columns%5B7%5D%5Bdata%5D=q1_status&columns%5B7%5D%5Bname%5D=&columns%5B7%5D%5Bsearchable%5D=true&columns%5B7%5D%5Borderable%5D=true&columns%5B7%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B7%5D%5Bsearch%5D%5Bregex%5D=false&columns%5B8%5D%5Bdata%5D=q2_output&columns%5B8%5D%5Bname%5D=&columns%5B8%5D%5Bsearchable%5D=true&columns%5B8%5D%5Borderable%5D=true&columns%5B8%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B8%5D%5Bsearch%5D%5Bregex%5D=false&columns%5B9%5D%5Bdata%5D=q2_status&columns%5B9%5D%5Bname%5D=&columns%5B9%5D%5Bsearchable%5D=true&columns%5B9%5D%5Borderable%5D=true&columns%5B9%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B9%5D%5Bsearch%5D%5Bregex%5D=false&columns%5B10%5D%5Bdata%5D=q3_output&columns%5B10%5D%5Bname%5D=&columns%5B10%5D%5Bsearchable%5D=true&columns%5B10%5D%5Borderable%5D=true&columns%5B10%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B10%5D%5Bsearch%5D%5Bregex%5D=false&columns%5B11%5D%5Bdata%5D=q3_status&columns%5B11%5D%5Bname%5D=&columns%5B11%5D%5Bsearchable%5D=true&columns%5B11%5D%5Borderable%5D=true&columns%5B11%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B11%5D%5Bsearch%5D%5Bregex%5D=false&columns%5B12%5D%5Bdata%5D=fye_output&columns%5B12%5D%5Bname%5D=&columns%5B12%5D%5Bsearchable%5D=true&columns%5B12%5D%5Borderable%5D=true&columns%5B12%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B12%5D%5Bsearch%5D%5Bregex%5D=false&columns%5B13%5D%5Bdata%5D=status&columns%5B13%5D%5Bname%5D=&columns%5B13%5D%5Bsearchable%5D=true&columns%5B13%5D%5Borderable%5D=true&columns%5B13%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B13%5D%5Bsearch%5D%5Bregex%5D=false&columns%5B14%5D%5Bdata%5D=created_at&columns%5B14%5D%5Bname%5D=&columns%5B14%5D%5Bsearchable%5D=true&columns%5B14%5D%5Borderable%5D=true&columns%5B14%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B14%5D%5Bsearch%5D%5Bregex%5D=false&columns%5B15%5D%5Bdata%5D=updated_at&columns%5B15%5D%5Bname%5D=&columns%5B15%5D%5Bsearchable%5D=true&columns%5B15%5D%5Borderable%5D=true&columns%5B15%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B15%5D%5Bsearch%5D%5Bregex%5D=false&columns%5B16%5D%5Bdata%5D=no_delete_mission&columns%5B16%5D%5Bname%5D=&columns%5B16%5D%5Bsearchable%5D=false&columns%5B16%5D%5Borderable%5D=false&columns%5B16%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B16%5D%5Bsearch%5D%5Bregex%5D=false&order%5B0%5D%5Bcolumn%5D=0&order%5B0%5D%5Bdir%5D=asc&start=0&length=10&search%5Bvalue%5D=bb&search%5Bregex%5D=false&_=1530222117292"
> for 127.0.0.1 at 2018-06-28 22:42:29 +0100 Processing by
> MissionsController#index as JSON Parameters: {"draw"=>"3",
> "columns"=>{"0"=>{"data"=>"fy", "name"=>"", "searchable"=>"true",
> "orderable"=>"true", "search"=>{"value"=>"", "regex"=>"false"}},
> "1"=>{"data"=>"associate_email", "name"=>"", "searchable"=>"true",
> "orderable"=>"true", "search"=>{"value"=>"", "regex"=>"false"}},
> "2"=>{"data"=>"guild_name", "name"=>"", "searchable"=>"true",
> "orderable"=>"true", "search"=>{"value"=>"", "regex"=>"false"}},
> "3"=>{"data"=>"coordinator_email", "name"=>"", "searchable"=>"true",
> "orderable"=>"true", "search"=>{"value"=>"", "regex"=>"false"}},
> "4"=>{"data"=>"name", "name"=>"", "searchable"=>"true",
> "orderable"=>"true", "search"=>{"value"=>"", "regex"=>"false"}},
> "5"=>{"data"=>"eighty", "name"=>"", "searchable"=>"true",
> "orderable"=>"true", "search"=>{"value"=>"", "regex"=>"false"}},
> "6"=>{"data"=>"q1_output", "name"=>"", "searchable"=>"true",
> "orderable"=>"true", "search"=>{"value"=>"", "regex"=>"false"}},
> "7"=>{"data"=>"q1_status", "name"=>"", "searchable"=>"true",
> "orderable"=>"true", "search"=>{"value"=>"", "regex"=>"false"}},
> "8"=>{"data"=>"q2_output", "name"=>"", "searchable"=>"true",
> "orderable"=>"true", "search"=>{"value"=>"", "regex"=>"false"}},
> "9"=>{"data"=>"q2_status", "name"=>"", "searchable"=>"true",
> "orderable"=>"true", "search"=>{"value"=>"", "regex"=>"false"}},
> "10"=>{"data"=>"q3_output", "name"=>"", "searchable"=>"true",
> "orderable"=>"true", "search"=>{"value"=>"", "regex"=>"false"}},
> "11"=>{"data"=>"q3_status", "name"=>"", "searchable"=>"true",
> "orderable"=>"true", "search"=>{"value"=>"", "regex"=>"false"}},
> "12"=>{"data"=>"fye_output", "name"=>"", "searchable"=>"true",
> "orderable"=>"true", "search"=>{"value"=>"", "regex"=>"false"}},
> "13"=>{"data"=>"status", "name"=>"", "searchable"=>"true",
> "orderable"=>"true", "search"=>{"value"=>"", "regex"=>"false"}},
> "14"=>{"data"=>"created_at", "name"=>"", "searchable"=>"true",
> "orderable"=>"true", "search"=>{"value"=>"", "regex"=>"false"}},
> "15"=>{"data"=>"updated_at", "name"=>"", "searchable"=>"true",
> "orderable"=>"true", "search"=>{"value"=>"", "regex"=>"false"}},
> "16"=>{"data"=>"no_delete_mission", "name"=>"", "searchable"=>"false",
> "orderable"=>"false", "search"=>{"value"=>"", "regex"=>"false"}}},
> "order"=>{"0"=>{"column"=>"0", "dir"=>"asc"}}, "start"=>"0",
> "length"=>"10", "search"=>{"value"=>"bb", "regex"=>"false"},
> "_"=>"1530222117292"} ActiveRecord::SessionStore::Session Load
> (3.6ms) SELECT "sessions".* FROM "sessions" WHERE
> "sessions"."session_id" = $1 ORDER BY "sessions"."id" ASC LIMIT 1
> [["session_id", "1f1458aac34369eaa4ce2ddcd835c07c"]] User Load
> (1.3ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 ORDER
> BY "users"."id" ASC LIMIT 1 [["id", 58]] User Load (0.9ms) SELECT
> "users".* FROM "users" WHERE "users"."id" = 58 ORDER BY "users"."id"
> ASC LIMIT 1 (0.8ms) SELECT "tribes"."region" FROM "tribes" WHERE
> (region is not null) (2.3ms) SELECT COUNT(*) FROM "missions" INNER
> JOIN "associates" ON "associates"."id" = "missions"."associate_id"
> INNER JOIN "associates" "coordinators_missions" ON
> "coordinators_missions"."id" = "missions"."coordinator_id" Completed
> 500 Internal Server Error in 32ms (ActiveRecord: 14.2ms)
>
> NameError (uninitialized constant Coordinator):
> app/controllers/missions_controller.rb:15:in `block (2 levels) in
> index' app/controllers/missions_controller.rb:11:in `index'
edit2: код контроллера
def index
respond_to do |format|
format.html
format.json do
render json: ::MissionDatatable.new(view_context, {region: get_current_user_region_filter})
end
end
end