我目前正在为波士顿地区的国际学生建立一个类似Reddit风格社区的铁路平台。我仍在测试接收我的想法。我使用简单的形式和载波。我在注册方法中得到了这个@student = Student.new
实例。我在我的注册方法中也得到了@uploader = Student.new.picture
(使用了carrierwave)。这个想法是每个学生都有与他或她相关的图片。我在学生模型上安装了载波图片功能。我正在使用carrierwave_direct gem直接将图片上传到我在亚马逊上的s3存储空间。
我的signup.html.erb看起来像这样
<div class = "signupform">
<%= simple_form_for @student, :html => {:multipart => true} do |f| %>
<%= f.input :last_name, label: '姓'%>
<%= f.input :first_name, label: '名' %>
<%= f.input :email, label: '电子邮件' %>
<%= f.input :password, label: '密码' %>
<%= f.input :college, label: '大学' %>
<%= f.input :budget, label: '房间租金预算 (optional)' %>
<%= f.button :submit %>
<br>
Your picture is optional
<% end %>
<%= direct_upload_form_for @uploader do |f| %>
<p><%= f.file_field :picture %></p>
<%= f.button :submit %>
<% end %>
</div>
如何将其制作成一种形式?我的表单上有两个提交按钮,用户可以创建一个帐户但是被重定向到感谢页面,或者用户只能上传图片而不是创建帐户?
direct_upload_form_for直接是来自carrier direct的辅助视图方法,需要直接上传到s3我想?
答案 0 :(得分:0)
为什么使用两种形式而不是一种形式?在学生模型中包含图片上传。
<%= simple_form_for @student, :html => {:multipart => true} do |f| %>
<%= f.input :last_name, label: '姓'%>
<%= f.input :first_name, label: '名' %>
<%= f.input :email, label: '电子邮件' %>
<%= f.input :password, label: '密码' %>
<%= f.input :college, label: '大学' %>
<%= f.input :budget, label: '房间租金预算 (optional)' %>
<%= f.file_field :picture, label: 'student photo (optional)' %>
<%= f.button :submit %>
<br>
你能调用helper方法simple_form吗?如果您需要以这种方式形成它
<%= simple_form_for @student, :html => {:multipart => true} do |f| %>
<%= f.input :last_name, label: '姓'%>
<%= f.input :first_name, label: '名' %>
<%= f.input :email, label: '电子邮件' %>
<%= f.input :password, label: '密码' %>
<%= f.input :college, label: '大学' %>
<%= f.input :budget, label: '房间租金预算 (optional)' %>
<%= direct_upload_form_for @uploader do |f| %>
<p><%= f.file_field :picture %></p>
<%= f.button :submit %>
<br>