开发者

Rails simpleform pre data

开发者 https://www.devze.com 2023-03-09 20:08 出处:网络
How do I make a simple form association have pre data when editing? My form: <h1>Editing kategori</h1>

How do I make a simple form association have pre data when editing?

My form:

<h1>Editing kategori</h1>
<%= simple_form_for(@konkurrancer, :url => {:action => 'update', :id => @konkurrancer.id }) do |f| %>
    <%= f.association :kategoris  %>
    <%= f.butto开发者_开发知识库n :submit, :value => 'Edit konkurrence' %>
<% end %>


You almost did it:

<%= f.button :submit, :value => 'Edit konkurrence', :data_pre => "whatever here" %>


Your best bet is to do something like this in your controller:

def edit
  @konkurrancer = Konkurrancer.new(:title => "hello wurld", :description => "blah blah blah", :nuclear_level => 10)
end

Then your form should automatically populate these values as "pre data".

0

精彩评论

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