我有一个页面,用户可以在其中上传作业。在编辑页面上,我有一个循环遍历所有现有作业并为每个作业打印一个表单。问题是,我不知道如何告诉控制器中的更新操作要更新哪个作业。这是编辑页面:
<% @currentjobs.each do |thejob| %>
<%= simple_form_for(thejob) do |f| %>
<%= f.error_notification %>
<%= f.input :firm, input_html: { class: 'field' }, label: "Firm" %> <br>
<%= f.input :position, input_html: { class: 'field' }, label: "Position" %> <br>
<%= f.input :category, input_html: { class: 'field' }, label: "Category"%>
<%= f.input :begin, input_html: { class: 'field' }, label: "Beginning", collection: 1960..2013 %><br>
<%= f.input :end, input_html: { class: 'field' }, label: "End", collection: 1960..2013 %>
<%= f.input :description, input_html: { class: 'field' }, label: "Description"%>
<div class="form-actions">
<%= f.submit "Save" %>
</div>
<% end %>
<% end %>
这是更新操作:
def update
thejob = current_user.profile.jobs.where(:id => params[:id])
thejob.update_attributes(job_params)
flash[:success] = "You have succesfully updated your info"
redirect_to profile_path(current_user.profile_name)
end
我知道这与我调用表单的更新操作有关。我想我叫错了。
更新:以下是此视图生成的表单(请记住没有样式):
这是我的工作路线代码:
resources :jobs
这是rails生成的html:
<h1>edit page for jobs </h1>
<form accept-charset="UTF-8" action="/jobs/9" class="simple_form edit_job" id="edit_job_9" method="post"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="✓" /><input name="_method" type="hidden" value="patch" /><input name="authenticity_token" type="hidden" value="woHDLDSOUhEA6AZU1TDVbOVW1el6lUVL3evDF/svInc=" /></div>
<div class="input string required job_firm"><label class="string required" for="job_firm"><abbr title="required">*</abbr> Firm</label><input aria-required="true" class="string required fsield" id="job_firm" maxlength="80" name="job[firm]" required="required" size="80" type="text" value="alan iverson falkjf kjfh fsdlkjh " /></div> <br>
<div class="input string required job_position"><label class="string required" for="job_position"><abbr title="required">*</abbr> Position</label><input aria-required="true" class="string required fsield" id="job_position" maxlength="80" name="job[position]" required="required" size="80" type="text" value="position 3" /></div> <br>
<div class="input string optional job_category"><label class="string optional" for="job_category">Category</label><input class="string optional fsield" id="job_category" maxlength="255" name="job[category]" size="255" type="text" value="" /></div>
<div class="input select required job_begin"><label class="select required" for="job_begin"><abbr title="required">*</abbr> Beginning</label><select aria-required="true" class="select required fsield" id="job_begin" name="job[begin]" required="required"><option value=""></option>
<option value="1960">1960</option>
<option value="1961">1961</option>
.
.
.
<div class="input select required job_end"><label class="select required" for="job_end"><abbr title="required">*</abbr> End</label><select aria-required="true" class="select required fsield" id="job_end" name="job[end]" required="required"><option value=""></option>
<option selected="selected" value="1960">1960</option>
<option value="1961">1961</option>
.
.
.
<div class="input text required job_description"><label class="text required" for="job_description"><abbr title="required">*</abbr> Description</label><textarea aria-required="true" class="text required fsield" id="job_description" maxlength="500" name="job[description]" required="required">
</textarea></div>
<div class="form-actions">
<input name="commit" type="submit" value="Save" />
</div><br><br>
</form>
<form accept-charset="UTF-8" action="/jobs/7" class="simple_form edit_job" id="edit_job_7" method="post"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="✓" /><input name="_method" type="hidden" value="patch" /><input name="authenticity_token" type="hidden" value="woHDLDSOUhEA6AZU1TDVbOVW1el6lUVL3evDF/svInc=" /></div>
<div class="input string required job_firm"><label class="string required" for="job_firm"><abbr title="required">*</abbr> Firm</label><input aria-required="true" class="string required fsield" id="job_firm" maxlength="80" name="job[firm]" required="required" size="80" type="text" value="asf asd fasf asd fas as fsaf sd" /></div> <br>
<div class="input string required job_position"><label class="string required" for="job_position"><abbr title="required">*</abbr> Position</label><input aria-required="true" class="string required fsield" id="job_position" maxlength="80" name="job[position]" required="required" size="80" type="text" value="position 2" /></div> <br>
<div class="input string optional job_category"><label class="string optional" for="job_category">Category</label><input class="string optional fsield" id="job_category" maxlength="255" name="job[category]" size="255" type="text" value="fafdsfds" /></div>
<div class="input select required job_begin"><label class="select required" for="job_begin"><abbr title="required">*</abbr> Beginning</label><select aria-required="true" class="select required fsield" id="job_begin" name="job[begin]" required="required"><option value=""></option>
.
.
.
<div class="input text required job_description"><label class="text required" for="job_description"><abbr title="required">*</abbr> Description</label><textarea aria-required="true" class="text required fsield" id="job_description" maxlength="500" name="job[description]" required="required">
</textarea></div>
<div class="form-actions">
<input name="commit" type="submit" value="Save" />
</div><br><br>
</form>
.
.
.