Ruby on rails 最佳位置gem不保存文本区域内容
所以,我不知道为什么,但当我在文本框中输入一些文本,然后刷新页面时,文本不会保存。我使用的是正确的DB字段(描述),所以我不确定出了什么问题 \u photo.html.erbRuby on rails 最佳位置gem不保存文本区域内容,ruby-on-rails,ruby-on-rails-4,best-in-place,Ruby On Rails,Ruby On Rails 4,Best In Place,所以,我不知道为什么,但当我在文本框中输入一些文本,然后刷新页面时,文本不会保存。我使用的是正确的DB字段(描述),所以我不确定出了什么问题 \u photo.html.erb <%= best_in_place photo, :description, type: :textarea, nil: 'Enter a Caption' %> 为什么不节约呢 干杯 更新: class PhotosController < ApplicationController befor
<%= best_in_place photo, :description, type: :textarea, nil: 'Enter a Caption' %>
为什么不节约呢
干杯
更新:
class PhotosController < ApplicationController
before_filter :authenticate_user!
def show
@photo = current_user.photos.find(params[:id])
end
show.js
$('.modal-title').html('<%= @photo.title %>');
$('.modal-body').html('<%= j(render "modal_photo", photo: @photo) %>');
$('#myModal').modal();
$('.modal title').html('');
$('.modal body').html('');
$('#myModal').modal();
照片\u控制器(snip):
class PhotosController < ApplicationController
before_filter :authenticate_user!
def show
@photo = current_user.photos.find(params[:id])
end
class photocontroller
这里您需要保存对象而不是单值属性。换成
<%= best_in_place @photo, :description, type: :input %>
请参阅此答案帮助:我认为您的问题可能出在控制器上:
class PhotosController < ApplicationController
respond_to :html, :json # Whatever formats you want to respond
# Other actions...
def update
@photo = Photo.find(params[:id])
respond_to do |format|
if @photo.update_attributes(params[:photo])
format.html { # Whatever you want to do... }
format.json { respond_with_bip(@photo) }
else
format.html { # Whatever you want to do... }
format.json { respond_with_bip(@photo) }
end
end
end
class photocontroller
Best-in-place提供了一种实用方法,您应该在控制器中使用它,以便使用
:json
格式提供javascript端期望的响应 请添加控制器的内容和调用\u photo.html.erb
partial的视图。当然-我已经用show和photos控制器的相关代码更新了帖子。谢谢请也添加控制器的更新
操作。您正在使用Rails3或Rails4?Rails 4。让我把它拿走,对不起!