I used
gem 'rails', '4.2.8'
gem 'carrierwave', '~> 1.2', '>= 1.2.2'
gem 'mini_magick', '~> 4.8'
gem 'Jcrop', '~> 0.1.0'
and then I write the code as it
https://www.driftingruby.com/episodes/cropping-images-with-jcrop
It works good.
But the problem is when I want to change the crop.html.erb
to use Bootstrap
_modal.html.erb
, How should change the user_controller.erb
?
the original codes is like this :
def update
@user = User.find(params[:id])
if @user.update_attributes(user_params)
if params[:user][:picture].present?
render :crop ###this how to change use modal.html
else
redirect_to @user
flash[:success] = "更新成功"
end
else
render :edit
end
end
I had try as
https://stackoverflow.com/questions/37819575/how-to-show-modal-window-in-controllers-action?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa
And the new user_controller.erb
def update
@user = User.find(params[:id])
if @user.update_attributes(user_params)
if params[:user][:picture].present?
respond_to do |format| ##change here
format.js ##change here
end ##change here
else
redirect_to @user
flash[:success] = "更新成功"
end
else
render :edit
end
end
But it always show that :
ActionController::UnknownFormat
If add format.html
,it has wrongs templates missing
, because I write the html codes in show.html.erb
,it likes:
<%= form_for @user, :html => {:multipart => true} do |f| %>
<div class="row " id="user_avatar_crop">
<!-- Choose picture -->
<div class="col-md-12">
<%= f.file_field :picture, id: :user_avatar, :onchange => 'this.form.submit()' %>
</div>
</div>
<!-- Modal -->
<% end %>
<div class="userAvatarUpload">
</div>
<%= image_tag @user.picture_url(:thumb) if @user.picture? %>
How should I format.html
to show.html.erb
?
My questions just like this:
https://stackoverflow.com/questions/21027034/rails-carrierwave-jcrop-bootstrap
Should I just had to use paperclip like him? Is there any method to solve this problem?