В моем проекте у меня есть API и связанная с ним клиентская часть. Я использую рельсы версии 5. Создаю две модели. Один - пользователь, а другой - квалификация. Ассоциации приведены ниже.
class User
include Her::Model
include Her::FileUpload
has_file_upload :image_url
has_many :videos
has_many :qualifications
attributes :name, :email, :phone, :image_url, :contact_email, :about, :password, :password_confirmation
custom_post :sign_in, :refresh
custom_get :me
accepts_nested_attributes_for :qualifications
end
И квалификационная модель
class Qualification
include Her::Model
belongs_to :user
attributes :school, :degree, :grade, :start_year, :end_year
end
Мои сильные параметры в контроллере пользователей:
def user_params
user: params.require(:user).permit(:id, :name, :email, :phone, :contact_email, :about,:image_url,
{specialization_ids: []},
qualifications_attributes: [:id, :school, :degree, :grade, :start_year, :end_year, :_destroy]
end
Моя пользовательская форма, в которой я указал nested_form,
<div class="row">
<div class="container">
<div class="signup-bg col-md-12">
<h3 style="color:white;"> General Info </h3>
<hr>
<%= simple_nested_form_for @user do |f| %>
<%= f.input :email, input_html: {class: "input-user-form"} %>
<%= f.input :name, input_html: {class: "input-user-form"} %>
<%= f.input :phone , input_html: {class: "input-user-form"}%>
<%= f.input :contact_email, input_html: {class: "input-user-form"} %>
<%= f.input :about, as: :text, input_html: {class: "input-user-form"}%>
<label class="control-label">Selected Specializations</label>
<ul class="list-group">
<% @user.specializations.each do |sp| %>
<li class="list-group-item tags">
<%= check_box_tag "user[specialization_ids][]", sp["id"], true%>
<%= sp["name"] %>
</li>
<% end %>
</ul>
<h4 style="color:white;"><center>Select Your Specializations</center></h4>
<div class="row">
<div class="col-md-12">
<div class="input-group">
<input id="searchText" type="text" class="input-signup" placeholder="Search Specialization" style="z-index:0;">
<span class="input-group-btn">
<button class="btn btn-default btn-go" type="button">Go!</button>
</span>
</div>
<div class="col-md-12 col-sm-12 col-lg-12" id="specializationHolder" style="min-height:85px;"></div>
</div>
</div>
<h3 style="color:white;"> Qualification Info </h3>
<hr>
<div id="qualification_holder">
<%= f.simple_fields_for :qualifications, @qualification do |g| %>
<%= g.input :school,input_html: {class: "input-user-form"} %>
<%= g.input :degree, input_html: {class: "input-user-form"} %>
<%= g.input :grade, as: :integer, input_html: {class: "input-user-form"} %>
<%= g.input :start_year, required: false, as: :string, input_html: {type: :date, class: "datepicker input-user-form"} %>
<%= g.input :end_year, required: false, as: :string, input_html: {type: :date, class: "datepicker input-user-form"} %>
<% end %>
</div>
</br>
<div class="col-md-4">
<%= f.link_to_add :qualifications, data: {target: "#qualification_holder"}, class: "btn-signup-submit" do %>
<b> + </b> Add Qualifications
<% end %>
</div>
<div id="wrapper">
<label class="control-label file optional" for="user_image_url">Profile Picture</label>
<input class="file optional" type="file" name="user[image_url]" id="fileUpload">
</div>
<div class="form-group text-center">
<button type="submit" class="btn-signup-submit">Save Changes</button>
</div>
<% end %>
</div>
</div>
</div>
Но я получаю сообщение об ошибке undefined error «Reflect_on_association», указывающее на «link_to_add». Я застрял здесь на неделю. Есть какие-то решения по этому поводу .. Если да, то помогите пожалуйста.
Заранее спасибо.
:quualifications
быть опечаткой? Вы, наверное, имели в виду:qualifications
- person Jan Klimo   schedule 13.10.2017link_to_add
ожидает, что текст ссылки будет первым параметром. Вы пробовали делатьf.link_to_add "Add a qualification", :qualifications
- person Jan Klimo   schedule 13.10.2017