2013-10-23 171 views
0

晚上好,我一直想爲弄清楚爲什麼當我提出inspect.params我得到ID =>「ID」更新屬性不好,更新屬性。 id =>「id」?

請參閱我有更新的代碼:從管理形式批准真的,不更新屬性。我想這件事情,我只是俯瞰

形式index.html.erb

<% @snippets.each do |snippet| %> 
    <tr> 
     <td><%= link_to snippet.content %></td> 
     <td><%= snippet.created_at.to_date %></td> 
     <td><%= render snippet %></td> 
     <td>Status</td> 
<td><%= button_to 'Approve', active_snippet_path(snippet.id) %></td> 
</tr> 

控制器(片段#批准)

def approve 
    #@snippet = @book.snippet.find(params[:id]) 
    if @snippet.update_attribute(:approved, true) 
    redirect_to users_path 
    else 
    render root_path 
    end 
end 

錯誤正在引起該位明顯但不肯定爲什麼:

def find_book 
    raise params.inspect 
    @book = Book.find(params[:id]) 
    @snippet = @book.snippets 
    return @book 
    end 
end 

這是我得到的檢查。

{"authenticity_token"=>"D70njMSz3iYbVcCCkFIlolPBKeZUsVtFL5pabRT1CMo=", "controller"=>"snippets", "action"=>"approve", "id"=>"id"} 

請讓我知道你是否需要別的東西。我想明白爲什麼這個放置不適用於嵌套模型。

+0

您在檢查什麼? – dax

+0

向我們展示您的批准行動路線。從哪裏調用find_book方法? – usha

回答

0

問題是你有什麼似乎是你設置爲@snippet的片段(@ book.snippets)數組,並且正試圖使用​​只適用於一個實例的update_attribute方法。如果要更新陣列,可以使用以下內容:

Snippet.where(book_id: params[:id]).update_all(approved: true)