Datamapper通过表单更新枚举值

时间:2010-11-29 10:10:54

标签: ruby routes sinatra datamapper erb

我有一个这样的模型:

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

表单需要传递给路由以更新状态的值是什么?在这种情况下,路线应该是什么样的?

谢谢,

1 个答案:

答案 0 :(得分:2)

“打开”和“关闭” - 它们将自动转换为符号。