开发者

Datamapper update enum value through form

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<开发者_Go百科;/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,


"open" and "closed" - they will be converted to symbols automatically.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜