我正在使用Paperclip将图像添加到我的模型AgentActivity中,它按原样显示在表单上,但是当我更新表单时,它似乎没有保存。我的控制器更新方法正在保存除图像以外的所有参数,因此我认为它设置正确,但是我看不到哪里出错了?我还根据提供的文档设置了model.rb文件...
表格
> Z=5
> round(367.8/Z)*Z
[1] 370
> round(367.2/Z)*Z
[1] 365
控制器更新方法
// current value of the location href attribute
let currentURL = $(location).attr("href");
// value we intend to change it to
let redirectURL = "https://yellow.brick.road/"
if (currentURL !== redirectURL) {
$(location).attr("href", redirectURL);
} else {
location.reload();
}
Params
<%= image_tag @submission.agent_activities.last.image.url(:large) %>
<%= form_for @submission, html: { multipart: true } do |f| %>
<%= f.fields_for :agent_activity do |a|%>
<td> <div class="field">
<%= select_tag(:Status, options_for_select([['In Progress', 1], ['Not Interested', 2],['Viewing Arranged', 3]])) %>
</div>
</td>
<td> <div class="field">
<%= text_field_tag :Notes %>
</div>
</td>
<%= f.file_field :image %>
<td>
<div class="actions">
<%= f.submit %>
</div>
</td>
<% end %>
<% end %>
agent_activity.rb
def update
respond_to do |format|
if user_signed_in?
@submission.update(submission_params)
format.html { redirect_to @submission, notice: 'Submission was successfully updated.' }
format.json { render :show, status: :ok, location: @submission }
else
if agent_signed_in?
#AgentActivity.create(agent_activity_params)
AgentActivity.create(agent_id: current_agent.id, submission_id: @submission.id, Notes: agent_activity_params[:Notes], Status: agent_activity_params[:Status] , image: agent_activity_params[:image])
format.html { redirect_to @submission, notice: 'Activity was successfully updated.' }
format.json { render :show, status: :ok, location: @submission }
else
format.html { render :edit }
format.json { render json: @submission.errors, status: :unprocessable_entity }
end
end
end
结束
Schema.rb
def agent_activity_params
params.permit(:id, @submission.id, :Status, :Notes, :image)
end
答案 0 :(得分:0)
避免回形针。使用Rails自己的功能ActiveStorage,因为回形针已弃用。您可以在回形针gem文档中获取详细信息。