I am building a job app with rails. In my job 'new' page, I have a preview functionality where a user can click on the 'preview' button to have a look at how the job posting would look like. In creating the job, the user would need to upload a company logo. I would like to find a way of previewing the company logo on the create.html.erb. I am using Carrierwave.
I have checked out solutions like rails preview image but that seems to work on only new.html.erb. My aim is to display the preview in create.html.erb
In my new.html.erb, i have
<%= f.input :unregistered_company_logo, :label => "Company Logo" %>
<%= f.input :unregistered_company_logo_cache, as: :hidden %>
<%= f.button :submit , name: "previewButt", value: "Preview", formtarget:"_blank", data: { disable_with: false }%>
In the create.html.erb, I have
<%= image_tag @job.unregistered_company_logo, class: "show-logo" %>
In the create action, i have
def create
@job = Job.new(job_params)
if params[:previewButt] == "Preview"
flash[:alert] = "This is a PREVIEW of your job posting. Go back to the previous tab to Post the job or make edits."
render :create
elsif
params[:createButt] == "Post Job"
@job.save
flash[:notice] = "Success!"
redirect_to @job
else
render :new
end
end
How do i preview the uploaded logo in create.html.erb page so the user can see how exactly it would look like on show.html.erb. As i mentioned, the solutions that i have seen online seem to only display the preview on new.html.erb.