Rails - 在前端编辑数据,就像在 Linkedin 的个人资料页面中一样
Rails - Edit data on front-end like in Linkedin's profiles pages
是否可以在 RoR 网络应用程序中允许用户编辑显示页面中的元素?
目标类似于 Linkedin,当您编辑自己的个人资料页面时(将鼠标移到某个字段上可以进行编辑)。他们是怎么做到的?它是在显示页面还是编辑页面上?我们需要什么样的前端技术?
我不太喜欢传统的 'Edit.html' 和 'Show.html'。
非常感谢! :)
是的,您可以将显示页面用作编辑页面。您可以将控制器设置为与此类似的东西:
your_controller.rb
class YourController < Application Controller
before_filter :show_user
def show
render :edit
end
def edit; end
private
def show_user
@user = current_user
end
end
另外不要忘记此控制器中的 'update' 方法和您传递的参数。然后您可以创建 edit.html 视图作为显示页面,但允许进行编辑。至于堪比LinkedIn的编辑,你可以使用'best_in_place' gem进行内联编辑。在这里找到:https://github.com/bernat/best_in_place
是否可以在 RoR 网络应用程序中允许用户编辑显示页面中的元素?
目标类似于 Linkedin,当您编辑自己的个人资料页面时(将鼠标移到某个字段上可以进行编辑)。他们是怎么做到的?它是在显示页面还是编辑页面上?我们需要什么样的前端技术?
我不太喜欢传统的 'Edit.html' 和 'Show.html'。
非常感谢! :)
是的,您可以将显示页面用作编辑页面。您可以将控制器设置为与此类似的东西:
your_controller.rb
class YourController < Application Controller
before_filter :show_user
def show
render :edit
end
def edit; end
private
def show_user
@user = current_user
end
end
另外不要忘记此控制器中的 'update' 方法和您传递的参数。然后您可以创建 edit.html 视图作为显示页面,但允许进行编辑。至于堪比LinkedIn的编辑,你可以使用'best_in_place' gem进行内联编辑。在这里找到:https://github.com/bernat/best_in_place