Datamapper通过表单更新枚举值
我有一个这样的模型:
class Project
include DataMapper::Resource
property :id, Serial
property :title, String
property :slug, String
property :status, Enum[:open, :closed ], :default => :open
has n, :issues
end
我创建了一个视图来更新项目状态:
<form action="/project/update" method="post" id="project">
<label for="status">Status
<select id="status">
<option value="0"
<% if(@project.status == :open) %>
selected="selected"
<% end %>
>Open</option>
<option value="1"
<% if(@project.status == :closed) %>
selected="selected"
<% end %>
>Closed</option>
</select>
</label>
</form>
这是路线:
post '/project/update' do
@project = Project.get(params[:project_id])
@project.update(:title => params[:title])
end
表单需要传递给路线什么值来更新状态?在这种情况下,路线应该是什么样的?
谢谢,
I have a model like this:
class Project
include DataMapper::Resource
property :id, Serial
property :title, String
property :slug, String
property :status, Enum[:open, :closed ], :default => :open
has n, :issues
end
I've created a view to update the project status:
<form action="/project/update" method="post" id="project">
<label for="status">Status
<select id="status">
<option value="0"
<% if(@project.status == :open) %>
selected="selected"
<% end %>
>Open</option>
<option value="1"
<% if(@project.status == :closed) %>
selected="selected"
<% end %>
>Closed</option>
</select>
</label>
</form>
Here's the route:
post '/project/update' do
@project = Project.get(params[:project_id])
@project.update(:title => params[:title])
end
What values does the form need to pass to the route to update the status? and what should the route look like in this instance?
Thanks,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
“打开”和“关闭” - 它们将自动转换为符号。
"open" and "closed" - they will be converted to symbols automatically.