✅, 如何移除simple_form
- rails destroy install:simple_form
- 去掉gemfile中的gem 'simple_form'
- bundle
⚠️,如果使用了80template则还会出现问题。
✅(已经解决)导航栏,部分项目不能靠右排列。
在<div class="navbar-nav">中添加 mr-auto,或者flex-grow-1可以把兄弟<div>挤压到边上。
- mr-auto改变margin
- flex-grow-1改变padding-right
✅(已经解决) devise 默认的是html.erb格式。以下是改变方法:
https://github.com/plataformatec/devise/wiki/How-To:-Create-Haml-and-Slim-Views
另外devise不符合国内的使用。国内多用手机登陆。
✅ 备注:method不要写成mehtod,否则会报告❌
✅如何使用render渲染 namespace中product
这不是一个问题,同一个controller,直接render就行。在_form中,参数是[:admin, @product]
✅ (已解决,改用form_with)
使用 active_storage储存图片: 不会使用has_many_attached :avatar上传多个文件。
simple_form不会使用,下面的语句不能正确生产choose files
❌= f.input :images, :multiple => true
我改用form_for: ✅ok了。
就会在view中显示一个按键:choose files,⚠️是files, 这样就可以上传多个文件了。✌️。
✅ (已解决)如何使用namespaced routes,像admin_post_url。
= form_with(model: [:admin, @post]) do |form|
...
deise:提示信息无法更新成中文。并说translate missing:
包括: 登陆,退出,等。。。
使用了simple_form, 具体如何修改,如中文显示,还没有看。
起点:
假设@post有一个image
file_field(:image, accept: 'image/png,image/gif,image/jpeg')
:accept
- If set to one or multiple mime-types, the user will be suggested a filter when choosing a file. You still need to set up model validations.
✅ 已解决 。
问题:如何设置validations。验证上传文件的格式。自定义?
使用“how to validate uploaded file type in rails 5.2”进行google search
- 得到2018年的搜索记录。看第一条。
- 看相关的网页:
https://github.com/rails/rails/issues/31656 (还没有看。)
在product.rb中
validate :must_type
✅已解决。问题:如果对product进行edit,第一次点击更新按钮出现errors,第二次如果正确更新,会在index页面出现之前的flash❌提示。
def update
...
使用flash.now即可。
✅已解决,方法:brew upgrade imagemagic . imagemagick的版本旧了,需要更新为最新的。
不清楚,为什么使用 image.variant(resize: "400x400")出错
link_to image_tag(image.variant(resize: "400x400")), rails_blob_path(image, disposition:"attachment")
⚠️搁置,因为不会影响其他功能。
问题:提交出现错误提示,本应当渲染render :new,url却返回到了products.奇怪。
✅ 记录:如何使用插入一个占位图片image in placehold.it
image_tag("http://placehold.it/200x200&text=No Pic", size:"400")
会生成一个400*400的灰色方块。中间显示:No Pic
<img src="http://placehold.it/200x200"> #生成一个200的占位图框