When a user clicks on a featured_inspiration
, the intention is to populate a new _form with data from that featured_inspiration
. The data consists of :text
and/or :image
, allowing the user to save an existing Inspiration
to their list of Inspirations
.
The issue arises when :image
fails to prepopulate while :text
functions correctly.
controller
def new
existing_inspiration = Inspiration.find_by_id params[:inspiration_id]
if existing_inspiration
@inspiration = existing_inspiration.dup
@inspiration.image_file_name = existing_inspiration.dup.image_file_name
@inspiration.image_content_type = existing_inspiration.dup.image_content_type
@inspiration.image_file_size = existing_inspiration.dup.image_file_size
@inspiration.image_updated_at = existing_inspiration.dup.image_updated_at
else
@inspiration = current_user.inspirations.build
end
end
Console
[41] pry(main)> Inspiration.last
Inspiration Load (1.7ms) SELECT "inspirations".* FROM "inspirations" ORDER BY "inspirations"."id" DESC LIMIT 1
=> #<Inspiration:0x007fa6d15ec9a8
id: 13,
conceal: false,
user_id: 8,
created_at: Fri, 26 Feb 2016 15:29:52 EST -05:00,
updated_at: Fri, 26 Feb 2016 15:29:52 EST -05:00,
likes: nil,
name: "",
image_file_name: nil,
image_content_type: nil,
image_file_size: nil,
image_updated_at: nil>
_form
<%= simple_form_for(@inspiration, html: { data: { modal: true } }) do |f| %>
<%= f.file_field :image %>
<%= f.text_area :text %>
<% end %>
Here's how I got duplicating text to work.
UPDATE
suggested_inspirations
<% @inspirations.each do |inspiration| %>
<%= link_to inspiration_path(inspiration) do %>
<div class="box panel panel-default" style="width: 175px;">
<% if inspiration.image.present? %>
<div id="box">
<%= link_to new_inspiration_path(inspiration_id: inspiration.id), data: { modal: true } do %>
<div class="inspiration-image-button"><span class="glyphicon glyphicon-plus"></span></div>
<% end %>
<%= link_to image_tag(inspiration.image.url(:medium)), inspiration %>
</div>
<% end %>
<% if inspiration.name.present? %>
<div class="panel-body">
<%= link_to new_inspiration_path(inspiration_id: inspiration.id), data: { modal: true } do %>
<div class="inspiration-button"><span class="glyphicon glyphicon-plus"></span></div>
<% end %>
<%= inspiration.name %>
</div>
<% end %>
</div>
<% end %>
<% end %>