Note that there are some explanatory texts on larger screens.

plurals
  1. POUpdating Model Attributes Through Show Page
    primarykey
    data
    text
    <p>I am looking to allow a user to update a model's attributes through the model's show page, then submit, to display updated attributes. <code>:startdate</code> and <code>:enddate</code> are in my <code>attr_accesible</code> list for the <code>cart.rb</code> model. Based on the log it looks like it is taking the enddate and startdate but isn't setting it. Any thoughts? Thanks so much.</p> <p><strong>carts_controller.rb</strong></p> <pre><code>def show @cart = Cart.find(params[:id]) end def update @cart = Cart.find(params[:id]) respond_to do |format| if @cart.update_attributes(params[:cart]) format.html { redirect_to(@cart, :notice =&gt; 'Dates Set.') } format.xml { head :ok } end end end </code></pre> <p><strong>carts/show.html.erb</strong></p> <pre><code> &lt;%= form_for @cart do %&gt; From &lt;%= text_field_tag :startdate %&gt; &lt;/br&gt; To &lt;%= text_field_tag :enddate %&gt; &lt;%= submit_tag "Set Dates", :method =&gt; :put %&gt; &lt;% end %&gt; Rental Dates: &lt;%= @cart.startdate %&gt; &lt;%= @cart.enddate %&gt; </code></pre> <p><strong>development.log</strong></p> <pre><code>Started POST "/carts/42" for 127.0.0.1 at 2011-08-10 14:27:10 -0400 DEPRECATION WARNING: Setting filter_parameter_logging in ActionController is deprecated and has no longer effect, please set 'config.filter_parameters' in config/application.rb instead. (called from &lt;class:ApplicationController&gt; at /Users/willdennis/rails_projects/spinlister/app/controllers/application_controller.rb:8) Processing by CartsController#update as HTML Parameters: {"utf8"=&gt;"✓", "authenticity_token"=&gt;"2RC9jfvbdUWtlT3OWnVd1OhW7WigUPYVoS5Quuwv2hQ=", "startdate"=&gt;"08/10/2011", "enddate"=&gt;"08/18/2011", "commit"=&gt;"Set Dates", "id"=&gt;"42"} [1m[35mCart Load (1.1ms)[0m SELECT "carts".* FROM "carts" WHERE ("carts"."id" = 42) LIMIT 1 Redirected to http://localhost:3000/carts/42 Completed 302 Found in 82ms Started GET "/carts/42" for 127.0.0.1 at 2011-08-10 14:27:10 -0400 DEPRECATION WARNING: Setting filter_parameter_logging in ActionController is deprecated and has no longer effect, please set 'config.filter_parameters' in config/application.rb instead. (called from &lt;class:ApplicationController&gt; at /Users/willdennis/rails_projects/spinlister/app/controllers/application_controller.rb:8) Processing by CartsController#show as HTML Parameters: {"id"=&gt;"42"} [1m[36mCart Load (1.3ms)[0m [1mSELECT "carts".* FROM "carts" WHERE ("carts"."id" = 42) LIMIT 1[0m [1m[35mLineItem Load (0.4ms)[0m SELECT "line_items".* FROM "line_items" WHERE ("line_items".cart_id = 42) [1m[36mBike Load (1.6ms)[0m [1mSELECT "bikes".* FROM "bikes" WHERE ("bikes"."id" = 86) ORDER BY bikes.created_at DESC LIMIT 1[0m </code></pre> <p>Rendered layouts/_stylesheets.html.erb (1.5ms) [1m[35mUser Load (2.4ms)[0m SELECT "users".* FROM "users" WHERE ("users"."id" = 1) LIMIT 1 Rendered layouts/_header.html.erb (116.3ms) Rendered layouts/_footer.html.erb (1.3ms) Rendered carts/show.html.erb within layouts/application (398.2ms) Completed 200 OK in 431ms (Views: 399.6ms | ActiveRecord: 6.7ms)</p> <pre><code> Started GET "/stylesheets/application.css" for 127.0.0.1 at 2011-08-10 14:27:11 -0400 ActionController::RoutingError (No route matches "/stylesheets/application.css"): Rendered /Users/willdennis/.rvm/gems/ruby-1.9.2-p180@rails3tut/gems/actionpack- 3.0.1/lib/action_dispatch/middleware/templates/rescues/routing_error.erb within rescues/layout (1.3ms) </code></pre>
    singulars
    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.
 

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