Я использую Simple Form с моим Rails 4.Rails Partials и простые ответы на формы
У меня есть структура, которая имеет модели для каждого из проектов, областей и данных.
Данные относятся к областям, области относятся к проектам.
Я только что сделал частичный вид данных, которые должны отображаться на странице проектов, если ответ на вопрос в форме области равен true.
у меня есть:
Условный оператор в моих проектах показать представление, чтобы спросить, если ответ на вопрос в форме содержания проекта, правда, выглядит следующим образом:
<% if @project.scope.try(:data) == true %>
<%= render 'data/particulars'%>
<% end %>
вопрос в моей форме области видимости для:
<%= f.input :data, :as => :boolean, :label => false, :inline_label => true %>
A данных/_particulars парциальное в папке данных моих взглядов папку с:
<div class="containerfluid">
<div class="row">
<div class="col-md-10 col-md-offset-1">
<div class="dataheading">Detail of the data requested</div>
<div class="datasubtext"><%= @project.scope.try(:datum).try(:prim_sec) %>
<%= @project.scope.try(:datum).try(:qual_quant) %>
</div>
<div class="datageneral">
<%= @project.scope.try(:datum).try(:survey_link) %>
<%= @project.scope.try(:datum).try(:other_description) %>
<%= @project.scope.datum.try(:data_description) %>
<% if @project.scope.try(:datum).try(:confidential) == true %>
Your confidential or commercially sensitive data will be protected with a standard Non-Disclosure Agreement, the form of which is here
</div>
<% end %>
</div>
</div>
</div>
Когда я тестирую страницу с проектами, с формой, которая отвечает на вопрос о сфере применения как истинный (чтобы данные отображались), ничего не отображается. Инспектор Google не распознает частичный вид данных.
В рельсах консоли, я попробовал:
SELECT "projects".* FROM "projects" WHERE "projects"."id" = 25
=> #<ActiveRecord::Relation [#<Project id: 25, title: "asdf ", description: "this is the overview", video_proposal: true, link_to_video_proposal: "IMG_0034.MOV", draft: false, expiry_date_for_sponsor_interest: "2015-05-10 00:00:00", slug: nil, created_at: "2015-04-10 04:53:05", updated_at: "2015-04-10 04:54:37", hero_image: "IMG_1631.JPG", motivation: "asdf asdf", approach: "asdf asdf", results: "asdf adfasdf ", completion_date: "2015-09-10", start_date: "2015-06-10", courses_id: nil, video_id: nil, recurring_project: true, frequency: "true", date_of_student_invitation: nil, date_for_student_interest: "2015-05-10", closed: false, student_id: nil, creator_id: 1, educator_id: nil, project_question_id: nil, project_answer_id: nil, published_date: nil, student_objective: "sdaf safasdf", industry_relevance: "asdf asdfaf", report: true, standard_licence: false, bespoke_licence: false, bespoke_licence_form: "", research_consulting: false, other_outcome: "0", industry_id: 7, limited_disclosure: nil, disclose: true>]>
2.1.1p76 :013 >
2.1.1p76 :008 > Scope.where(project_id: 25)
Scope Load (4.3ms) SELECT "scopes".* FROM "scopes" WHERE "scopes"."project_id" = 25
=> #<ActiveRecord::Relation [#<Scope id: 6, created_at: "2015-04-10 07:40:04", updated_at: "2015-04-10 07:40:04", if_datum: false, if_material: false, if_mentoring: false, if_participant: false, if_funding: false, if_ethic: true, if_group_research: false, project_id: 25, program_id: nil, proposal_id: nil>]>
2.1.1p76 :005 > puts Project.scope.try(:data).inspect
В результате я получаю этот запрос является: ArgumentError: неверное число аргументов (0 за 1..2) из/Users/мм /. rvm/gems/ruby-2.1.1/gems/activerecord-deprecated_finders-1.0.3/lib/active_record/deprecated_finders/base.rb: 70: in scope' from (irb):5 from /Users/mm/.rvm/gems/ruby-2.1.1/gems/railties-4.0.2/lib/rails/commands/console.rb:90:in
start ' из /Users/mm/.rvm/gems/ruby- 2.1.1/gems/railties-4.0.2/lib/rails/commands/console.rb: 9: in start' from /Users/mm/.rvm/gems/ruby-2.1.1/gems/railties-4.0.2/lib/rails/commands.rb:62:in
' из бункера/рельсов: 4: in require' from bin/rails:4:in
'
Однако, если я пытаюсь:
2.1.1p76 :010 > puts Scope.try(:datum).inspect
nil
=> nil
предложение Taryn в:
2.1.1p76 :013 > project = Project.find(25)
Project Load (34.8ms) SELECT "projects".* FROM "projects" WHERE "projects"."id" = $1 LIMIT 1 [["id", 25]]
=> #<Project id: 25, title: "asdf ", description: "this is the overview", video_proposal: true, link_to_video_proposal: "IMG_0034.MOV", draft: false, expiry_date_for_sponsor_interest: "2015-05-10 00:00:00", slug: nil, created_at: "2015-04-10 04:53:05", updated_at: "2015-04-10 04:54:37", hero_image: "IMG_1631.JPG", motivation: "asdf asdf", approach: "asdf asdf", results: "asdf adfasdf ", completion_date: "2015-09-10", start_date: "2015-06-10", courses_id: nil, video_id: nil, recurring_project: true, frequency: "true", date_of_student_invitation: nil, date_for_student_interest: "2015-05-10", closed: false, student_id: nil, creator_id: 1, educator_id: nil, project_question_id: nil, project_answer_id: nil, published_date: nil, student_objective: "sdaf safasdf", industry_relevance: "asdf asdfaf", report: true, standard_licence: false, bespoke_licence: false, bespoke_licence_form: "", research_consulting: false, other_outcome: "0", industry_id: 7, limited_disclosure: nil, disclose: true>
2.1.1p76 :014 > puts project.scope.try(:data)
Scope Load (2.1ms) SELECT "scopes".* FROM "scopes" WHERE "scopes"."project_id" = $1 ORDER BY "scopes"."id" ASC LIMIT 1 [["project_id", 25]]
=> nil
Следующие шаги:
2.1.1p76 :015 > puts project.inspect
#<Project id: 25, title: "asdf ", description: "this is the overview", video_proposal: true, link_to_video_proposal: "IMG_0034.MOV", draft: false, expiry_date_for_sponsor_interest: "2015-05-10 00:00:00", slug: nil, created_at: "2015-04-10 04:53:05", updated_at: "2015-04-10 04:54:37", hero_image: "IMG_1631.JPG", motivation: "asdf asdf", approach: "asdf asdf", results: "asdf adfasdf ", completion_date: "2015-09-10", start_date: "2015-06-10", courses_id: nil, video_id: nil, recurring_project: true, frequency: "true", date_of_student_invitation: nil, date_for_student_interest: "2015-05-10", closed: false, student_id: nil, creator_id: 1, educator_id: nil, project_question_id: nil, project_answer_id: nil, published_date: nil, student_objective: "sdaf safasdf", industry_relevance: "asdf asdfaf", report: true, standard_licence: false, bespoke_licence: false, bespoke_licence_form: "", research_consulting: false, other_outcome: "0", industry_id: 7, limited_disclosure: nil, disclose: true>
=> nil
2.1.1p76 :016 > puts project.scope.inspect
#<Scope id: 6, created_at: "2015-04-10 07:40:04", updated_at: "2015-04-10 07:40:04", if_datum: false, if_material: false, if_mentoring: false, if_participant: false, if_funding: false, if_ethic: true, if_group_research: false, project_id: 25, program_id: nil, proposal_id: nil>
=> nil
2.1.1p76 :017 > puts project.scope.try(:data).inspect
nil
=> nil
Проекты таблица:
t.string "title"
t.text "description"
t.boolean "video_proposal"
t.string "link_to_video_proposal"
t.boolean "draft", default: true
t.datetime "expiry_date_for_sponsor_interest"
t.string "slug"
t.datetime "created_at"
t.datetime "updated_at"
t.string "hero_image"
t.text "motivation"
t.text "approach"
t.text "results"
t.date "completion_date"
t.date "start_date"
t.integer "courses_id"
t.string "video_id"
t.boolean "recurring_project", default: true
t.string "frequency"
t.date "date_of_student_invitation"
t.date "date_for_student_interest"
t.boolean "closed", default: false
t.integer "student_id"
t.integer "creator_id"
t.integer "educator_id"
t.integer "project_question_id"
t.integer "project_answer_id"
t.date "published_date"
t.text "student_objective"
t.text "industry_relevance"
t.boolean "report"
t.boolean "standard_licence"
t.boolean "bespoke_licence"
t.string "bespoke_licence_form"
t.boolean "research_consulting"
t.text "other_outcome"
t.integer "industry_id"
t.string "limited_disclosure"
t.boolean "disclose", default: true
Scopes т возможность есть:
t.datetime "created_at"
t.datetime "updated_at"
t.boolean "if_datum", default: false
t.boolean "if_material", default: false
t.boolean "if_mentoring", default: false
t.boolean "if_participant", default: false
t.boolean "if_funding", default: false
t.boolean "if_ethic", default: true
t.boolean "if_group_research", default: false
t.integer "project_id"
t.integer "program_id"
t.integer "proposal_id"
Datum модель:
class Datum < ActiveRecord::Base
belongs_to :scope
end
Scope модель:
class Scope < ActiveRecord::Base
belongs_to :project
has_one :datum
accepts_nested_attributes_for :datum
end
Кто-нибудь знает, что я сделал не так?
Спасибо
Спасибо Taryn, но и потому, что у него есть одна базовая единица - это то, что для данных данные являются единственными. – Mel
Когда я пытаюсь: <% if @ project.scope.datum == true%> <% = render 'data/detailss'%> <% end %> – Mel
Нет, причина в том, что i-ые данные - это то, что вы написали 'has_one: datum' ... если вам нужны данные, тогда вы должны написать 'has_many: data' –