Я использую psql с моими рельсами 4 приложения.Rails Атрибуты не сохраняются в базе данных
У меня была модель рабочих проектов в течение довольно долгого времени, но с недавним изменением модели, которая полностью не связана, у меня теперь есть проблема, которая означает, что мои атрибуты формы проекта не создаются. Я смотрю в консоли, и атрибуты отмечены «ноль», хотя я их заполняю в новой форме проекта.
Элементы формы не сохраняются.
У меня есть контроллер модели проектов с разрешенным Params следующим образом:
def new
#authorise @project
@project = Project.new
@project.scope = Scope.new
@project.scope.datum = Datum.new
@project.scope.material = Material.new
@project.scope.mentoring = Mentoring.new
@project.scope.participant = Participant.new
@project.scope.funding = Funding.new
@project.scope.ethic = Ethic.new
@project.scope.group_research = GroupResearch.new
@project.scope.backgroundip = Backgroundip.new
end
У меня есть несколько вложенных атрибутов из других моделей. Параметры проекта включают в себя как атрибуты проекта, так и вложенные атрибуты.
def project_params
params[:project].permit(
:title, :description, :video_proposal, :link_to_video_proposal, :draft,
:expiry_date_for_sponsor_interest, :motivation, :approach,
:results, :completion_date, :start_date, :industry_id, :public, :recurring_project,
:frequency, :date_for_student_invitation, :date_for_student_interest, :closed, :student_objective,
:industry_relevance, :hero_image, :report, :standard_licence, :bespoke_licence, :bespoke_licence_form,
:research_consulting, :other_outcome,
scope_attributes: [:data, :materials, :mentoring, :participants, :participants, :funding, :ethics, :group, :project_id,
datum_attributes: [:prim_sec, :qual_quant, :survey, :survey_link, :experiment, :other_type, :other_description,
:confidential, :data_description, :scope_id],
material_attributes: [:mattype, :description, :scope_id],
mentoring_attributes: [:frequency, :description, :scope_id],
funding_attributes: [ :expenses, :honorarium, :financing, :currency, :size, :amount_expenses, :amount_honorarium,
:amount_principal_financing, :return_on_finance, :period_of_return, :expense_description, :scope_id],
participant_attributes: [ :title, :description, :location, :costs, :participation_cost, :eligibility, :eligibility_criteria,
:location_specific, :scope_id, :currency ],
group_research_attributes: [:number_of_group_members, :scope_id],
ethic_attributes: [:obtained, :date_expected, :ethics_comment, :ethics_policy_link, :scope_id],
backgroundip_attributes: [:scope_id, :copyright, :design, :patent, :trademark, :geographical_indication,
:trade_secret, :other, :identifier_copyright, :identifier_design, :identifier_patent,
:identifier_trademark, :identifier_geographical_indication, :identifier_trade_secret,
:identifier_other, :description, :registered_owner, :unregistered_interest, :conditions ]
]
)
params.require(:project).permit(:link_to_video_proposal)
end
У меня есть проект новой формы, которая имеет:
<%= simple_form_for @project do |f| %>
<% if @project.errors.any? %>
<div id="error_explanation">
<h2>Looks like there might be <%= pluralize(@project.errors.count, "error") %> with this project proposal. Take a look and let us know if we can help to sort them out.</h2>
<% end %>
<ul>
<% @project.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
</div>
</div>
<div class="row">
<div class="col-md-10 col-md-offset-1">
<div class="headerquestion-project">Project Overview
</div>
</div>
</div>
<div class="row">
<div class="col-md-3 col-md-offset-1">
<%= f.label 'Project title', :class => 'question-project' %>
</div>
<div class="col-md-7">
<%= f.input :title, label: false, placeholder: 'A catchy, relevant title for your project', :input_html => {:style=> 'width: 100%', class: 'response-project'} %>
</div>
</div>
Когда я пытаюсь заполнить форму и нажмите кнопку отправить, я получаю сообщение об ошибке, что заголовок не может быть пустым. Я добавляю заголовок, нажимаю кнопку «Отправить», и в представлении не отображается заголовок, а консоль показывает, что заголовок не сохранялся.
Любые идеи относительно того, как исправить эту проблему?
Спасибо
Попробуйте удалить последнюю строку из 'project_params' (' params.require (: project) .permit (: link_to_video_proposal) ') – makhan
Спасибо makhan. Это сработало. – Mel