Note that there are some explanatory texts on larger screens.

plurals
  1. POUpdate method not updating table using rails 4
    primarykey
    data
    text
    <p>I am having difficulty translating the Headfirst into Rails book which is based on Rails 2 into Rails 4 which is set up on my machine. The exercise is trying to retrieve a record from a database and then, once edited, update the table. I have tried many different ways and my current configuration is as follows - this will present the record for editing but will not actually update the record! (Infuriating!) NB - I am not using 'strong_parameters' nor 'protected_attributes' - I did try this but was getting stack to deep and other errors. My ad model is also empty - I have removed the att_accessible entries that I tried with the protected attributes gem.</p> <p>Here is my - ad controller entry:</p> <pre><code>def update @ad = Ad.find(params[:id]) @ad.update_attributes(update_params[:id]) redirect_to "/ads/#{@ad.id}" end private def update_params params.permit(:name, :description, :price, :seller_id, :email, :ad, :img_url) end end </code></pre> <p>EDIT VIEW:</p> <pre><code>&lt;h1&gt;Editing &lt;%= @ad.name %&gt;&lt;/h1&gt; &lt;%= form_for(@ad,:url=&gt;{:action=&gt;'update'}) do |f| %&gt; &lt;p&gt;&lt;b&gt;Name&lt;/b&gt;&lt;br /&gt;&lt;%= f.text_field :name %&gt;&lt;/p&gt; &lt;p&gt;&lt;b&gt;Description&lt;/b&gt;&lt;br /&gt;&lt;%= f.text_area :description %&gt;&lt;/p&gt; &lt;p&gt;&lt;b&gt;Price&lt;/b&gt;&lt;br /&gt;&lt;%= f.text_field :price %&gt;&lt;/p&gt; &lt;p&gt;&lt;b&gt;Seller&lt;/b&gt;&lt;br /&gt;&lt;%= f.text_field :seller_id %&gt;&lt;/p&gt; &lt;p&gt;&lt;b&gt;Email&lt;/b&gt;&lt;br /&gt;&lt;%= f.text_field :email %&gt;&lt;/p&gt; &lt;p&gt;&lt;b&gt;Img Url&lt;/b&gt;&lt;br /&gt;&lt;%= f.text_field :img_url %&gt;&lt;/p&gt; &lt;p&gt;&lt;%= f.submit "update" %&gt;&lt;/p&gt; &lt;% end %&gt; </code></pre> <p>Log Entry on Update:</p> <pre><code> Started PATCH "/ads/1/update" for 127.0.0.1 at 2013-08-13 22:35:51 +0100 Processing by AdsController#update as HTML Parameters: {"utf8"=&gt;"V", "authenticity_token"=&gt;"O4cN72FXCCkfkL7M6bozodbB0Aqor NctOOV5sfXdado=", "ad"=&gt;{"name"=&gt;"Typewriter", "description"=&gt;"Old manual typewr iter. Many years useful service. Works best with a bottle next to it.", "price"= &gt;"71.95", "seller_id"=&gt;"54", "email"=&gt;"dhammett@email.com1", "img_url"=&gt;"http:// homepage.mac.com/david_griffiths/typewriter.png"}, "commit"=&gt;"update", "id"=&gt;"1" } ←[1m←[35mAd Load (1.0ms)←[0m SELECT "ads".* FROM "ads" WHERE "ads"."id" = ? L IMIT 1 [["id", "1"]] Unpermitted parameters: utf8, _method, authenticity_token, ad, commit, id ←[1m←[36m (0.0ms)←[0m ←[1mbegin transaction←[0m ←[1m←[35m (0.0ms)←[0m commit transaction Redirected to http://localhost:3000/ads/1 Completed 302 Found in 54ms (ActiveRecord: 1.0ms) </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload