简体   繁体   English

如何在Ruby on Rails中生成此模型

[英]How to generate this model in Ruby on Rails

I am a beginner with Ruby on Rails but am trying to create my own application. 我是Ruby on Rails的初学者,但正在尝试创建自己的应用程序。

I've added users and a few models but am stuck on something.... I am trying to create a model called 'JOBS' with the following items: 我已经添加了用户和一些模型,但是仍然存在某些问题。...我试图创建一个名为“ JOBS”的模型,其中包含以下内容:

  • Job Title 职称
  • Job Category 工作类别
  • Job Tags 工作标签
  • Fixed Price or Hourly 固定价格或每小时
  • Budget 预算
  • Timeframe 大体时间
  • Description 描述
  • Files
  • Submit Button 提交按钮

Im not sure how to get the file upload form in there... 我不确定如何在那里获取文件上传表单...

If someone can point me in the right direction it would be greatly appreciated. 如果有人能指出我正确的方向,将不胜感激。

I recommend you try the CarrierWave gem . 我建议您尝试使用CarrierWave宝石

The docs are excellent, and show you how to create an upload form. 这些文档非常出色,并向您展示了如何创建上传表单。 CarrierWave is what many Rails professionals choose to use because it offers many conveniences, ways to upload multiple files at once, multiple backend storage systems such as Amazon S3, etc. CarrierWave是许多Rails专业人员选择使用的,因为它提供了许多便利,一次上传多个文件的方式,多个后端存储系统(例如Amazon S3等)。

For example, you could write a job that has a title and image like this: 例如,您可以编写具有标题和图像的作业,如下所示:

class ImageUploader < CarrierWave::Uploader::Base
  storage :file
end

class Job < ActiveRecord::Base
  mount_uploader :image, ImageUploader
end

Alternatively, if you're interested in learning how to do it in Rails without any gem, then read the Rails guides on form helpers for uploading files 另外,如果您有兴趣学习如何在没有任何gem的Rails中进行操作,请阅读表单助手上Rails指南以上传文件

For example, you could write a form that has a job title and image like this: 例如,您可以编写一个具有职位名称和图像的表单,如下所示:

<%= form_for @job do |f| %>
  <%= f.text_field :title %>
  <%= f.file_field :image %>
<% end %>

If you are uploading to Amazon S3 i found that using the Paperclip gem was pretty straight forward. 如果您上传到Amazon S3,我发现使用Paperclip gem非常简单。

Here is a walkthrough from Heroku: https://devcenter.heroku.com/articles/paperclip-s3 这是Heroku的演练: https//devcenter.heroku.com/articles/paperclip-s3

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM