У меня есть две модели 'activity_templates' и 'activity'.Я хочу создать ссылку на индекс activity_template, чтобы создать новое действие.Я хочу отправлять параметры activity_template в активную форму.Я хочу автоматически заполнить поле activity_template в новой форме активности.
Я не могу понять, как передать параметры на странице индекса.
Я думаю, что это проблема со ссылкой.
Ссылка:
<div class="box">
<div class="box-header">
<h3 class="box-title">Activities</h3>
</div>
<div class="box-body table-responsive no-padding">
<table class="table table-bordered">
<tbody>
<% @activity_templates.each do |activity_template| %>
<tr>
<td><a href="<%= new_app_activity_path(activity_template_id: @activity_template) %>"><%= activity_template.name %></a></td>
</tr>
<% end %>
</tbody>
</table>
<div class="text-right">
<%= will_paginate @activity_templates %>
</div>
</div>
</div>
URL:
http://localhost:3000/app/activities/new
Форма:
<%= simple_form_for([:app, @activity]) do |f| %>
<%= f.error_notification %>
<div class="form-inputs">
<div class="row">
<div class="col-md-6">
<%= f.association :resident, label_method: :full_name, prompt: "Choose a resident", collection: Resident.order(:first_name), selected: @resident.id %>
</div>
<div class="col-md-6">
<%= f.association :activity_template, collection: ActivityTemplate.order(:name).pluck(:name, :id), prompt: "Choose an activity template", selected: @activity_template.id %>
</div>
<div class="col-md-6">
<%= f.input :published_status, collection: ['Draft', 'Final'], default: 'Draft' %>
</div>
<div class="col-md-6">
<div class="form-group">
<label>Author</label>
<input class="form-control" type="text" placeholder="<%= @current_user.full_name %>" readonly value="<%= @activity.author.try(:full_name) %>">
</div>
</div>
</div>
<%= f.input :data %>
</div>
<div class="form-actions">
<%= f.button :submit %>
</div>
<% end %>
Контроллер активности:
def new
@activity = current_business.activities.new
if params[:resident_id].present?
@resident = Resident.find(params[:resident_id])
end
if params[:activity_template_id].present?
@activity_template = ActivityTemplate.find(params[:activity_template_id])
end
end