我有一個奇怪的問題,其中我的軌道中的一個表單沒有收到我的任何發佈數據。Rails表單提交空值或舊值
我的模型被稱爲條目,並且路線嵌套在廣告系列控制器中。提交新條目時,條目將被保存,但所有值都顯示爲空白,並且在編輯現有條目並單擊提交時,條目不會輸入任何輸入的新值,而是會恢復爲原始值。
我的代碼如下
/entries/_form.html.erb
<%= form_for [@campaign, @entry] do |f| %>
<div class="row">
<div class="left">
<%= f.label :name %>
</div>
<div class="right">
<%= f.text_field :name, :class => "textbox" %>
</div>
</div>
<div class="row tarow">
<div class="left">
<%= f.label :content %>
</div>
<div class="right">
<%= f.text_area :content %>
</div>
</div>
<div class="row tarow">
<div class="left">
<%= f.label :description %>
</div>
<div class="right">
<%= f.text_area :description %>
</div>
</div>
<div class="row">
<div class="left">
<%= f.label :provider %>
</div>
<div class="right">
<%= f.text_field :provider, :class => "textbox" %>
</div>
</div>
<div class="row">
<div class="left">
<%= f.label :image %>
</div>
<div class="right">
<%= f.text_field :image, :class => "textbox" %>
</div>
</div>
<div class="row">
<div class="left">
<%= f.label :url %>
</div>
<div class="right">
<%= f.text_field :url, :class => "textbox" %>
</div>
</div>
<div class="row">
<div class="left">
<%= f.label :votes %>
</div>
<div class="right">
<%= f.text_field :votes, :class => "textbox" %>
</div>
</div>
<div class="row">
<div class="left">
<%= f.label :hours %>
</div>
<div class="right">
<%= f.text_field :hours, :class => "textbox" %>
</div>
</div>
<div class="row">
<div class="left">
</div>
<div class="right">
<%= f.submit %>
</div>
</div>
<% end %>
entries_controller.rb
def new
@entry = Entry.new
respond_to do |format|
format.html # new.html.erb
format.xml { render :xml => @entry }
end
end
def edit
end
# POST /entries
# POST /entries.xml
def create
@entry = Entry.new(params[:entry])
@entry.user_id = current_user.id
@entry.campaign_id = @campaign.id
respond_to do |format|
if @entry.save
format.html { redirect_to(campaign_entry_path(@campaign.url, @entry) , :notice => 'Entry was successfully created.') }
format.xml { render :xml => @entry, :status => :created, :location => @entry }
else
format.html { render :action => "new" }
format.xml { render :xml => @entry.errors, :status => :unprocessable_entity }
end
end
end
def update
respond_to do |format|
if @entry.update_attributes(params[:entry])
format.html { redirect_to(campaign_entry_path(@campaign.url, @entry), :notice => 'Entry was successfully updated.') }
format.xml { head :ok }
else
format.html { render :action => "edit" }
format.xml { render :xml => @entry.errors, :status => :unprocessable_entity }
end
end
end