2013-02-17 88 views
0

試圖更新我在Ruby on Rails項目中發佈的帖子,但沒有任何反應。這真的很煩人,因爲我沒有得到任何錯誤,似乎無法弄清楚我做錯了什麼。Ruby on Rails - 編輯不工作

我認爲它很有用,但自從我第一次寫了不同的動作以來,我在「feed」模型中添加了多個內容,例如印象和標籤。不知道這影響了我的更新動作......

我的控制器看起來是這樣的:

def edit 
    @feed = Feed.find(params[:id]) 
    end 

    def update 
    @feed = Feed.find(params[:id]) 
    respond_to do |format| 
    if @feed.update_attributes(params[:feed]) 
     format.html { redirect_to @feed, notice: 'Feed was successfully updated.' } 
     format.json { head :no_content } 
    else 
     format.html { render action: "edit" } 
     format.json { render json: @feed.errors, status: :unprocessable_entity } 
    end 
    end 
    end 

我飼料模型是這樣的:

attr_accessible :content, :tag_list, :guid, :language, :location, :published_at, :summary, :url, :title, :user_id, :thumbnail_url, :url_to_feed, :type_of_feed 
    has_many :impressions, :as=>:impressionable 
    validates_length_of :tag_list, :maximum => 10 
    acts_as_taggable 

我的看法是這樣的:

<h1>Editing feed</h1> 

    <%= render 'form' %> 
    <%= link_to 'Show', @feed %> | 
    <%= link_to 'Back', feeds_path %> 

    ____________________ form 

    <%= form_for(@feed) do |f| %> 
    <% if @feed.errors.any? %> 
    <div id="error_explanation"> 
    <h2><%= pluralize(@feed.errors.count, "error") %> prohibited this feed from being saved:</h2> 
    <ul> 
    <% @feed.errors.full_messages.each do |msg| %> 
     <li><%= msg %></li> 
    <% end %> 
    </ul> 
    </div> 
    <% end %> 

<div class="field"> 
    <%= f.label :title %><br /> 
    <%= f.text_field :title %> 
</div> 
<div class="field"> 
    <%= f.label :content %><br /> 
    <%= f.text_area :content %> 
</div> 
    <div class="field"> 
    <%= f.label :location %><br /> 
    <%= f.text_field :location %> 
    </div> 
<div class="field"> 
    <%= f.label :language %><br /> 
    <%= f.text_field :language %> 
</div> 

    <div class="field"> 
<%= f.label :tag_list, "Tags (seperated by spaces)" %><br /> 
<%= f.text_field :tag_list %> 
    </div> 

    <div class="actions"> 
    <%= f.submit %> 
    </div> 
+0

你肯定叫你的編輯方法是什麼?在提交表單後立即查看log/development.log進行調試。您會在給定的日誌文件中找到控制器,操作和發送的參數。 – 2013-02-17 10:47:41

+0

感謝Sergey提供的回覆。 當我在development.log中查看時,我可以看到我的GET請求正在啓動編輯頁面:在2013-02-17 12:27:31 +0100開始GET「/ feeds/1/edit」for 127.0.0.1 ...「然後我有: 」Started PUT「/ feeds/1」for 127.0.0.1 at 2013-02-17 12:27:36 +0100 Processing by FeedsController#show as HTML「 – OXp1845 2013-02-17 11:18:48

回答

2

日誌條目

Started PUT "/feeds/1" for 127.0.0.1 at 2013-02-17 12:27:36 +0100 Processing by FeedsController#show as HTML 

說,PUT請求(發送您的表單數據)由FeedsController#show處理,但它必須由FeedsController#update處理。所以你的路線似乎是錯誤的。檢查出Rails Routing Guide

我會用飼料的ressource,因爲它會自動創建正確的路線:

resources :feeds 
+0

Thank you! 我確實擁有資源:在我的路線中添加資源,但需要將其移至頂部! – OXp1845 2013-02-17 13:24:31