开发者

Problem while editing a record

i treid to edit one record of my tables in rails 3 but ann error occured like this : ActiveRecord::RecordNotFound in WordsController#edit in my controller:

def edit
        @adverb =Adverb.find(:id)
  end

and in my view i h开发者_C百科ave :

 <% @adverb.each do |av| %>
            <tr class="<%= cycle("odd", "even") -%>">
            <td><%= av.name  %></td>
            <td><%= av.bedeutung %></td> 
            <td>
            <%= link_to 'edit',{:controller => 'words',:action => 'edit',:id=> av.id} %>
            </td>
            </tr>
 <% end %>

how can i solve this problem?


Try

@adverb = Adverb.find(params[:id])


its just

@adverb = Adverb.find(params[:id])

You dont need the .first option on the end thats only needed when using the where statement


:id is just a symbol, you are looking for that symbol's value inside the params hash

So instead of

Adverb.find(:id)

Use

Adverb.find(params[:id])

This will return a single record that matches the value of :id in params hash that is probably coming form you url /adverbs/:id

If there is no record with the provided ID, then an ActiveRecord::RecordNotFound exception will be raised, which in development will show you a stack trace page, and in production will show a 404 page.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜