开发者

Datamapper update enum value through form

开发者 https://www.devze.com 2023-01-27 22:47 出处:网络
I have a model like this: class Project include DataMapper::Resource property:id, Serial property:title, String

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

精彩评论

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

关注公众号