Note that there are some explanatory texts on larger screens.

plurals
  1. PORails Routing to New associated model
    primarykey
    data
    text
    <p>I have an App that has Households that visit my agency and I am logging each time a household visits. I select the household in the households index and open the visit view which is in the visits model in my index to select a household and create a new visit I have teh following code on my index view for households:</p> <pre><code> = link_to 'Visit', new_household_visit_path(household), class: 'btn btn-mini' </code></pre> <p>Rake Routes Shows:</p> <pre><code>new_household_visit GET /households/:household_id/visits/new(.:format) visits#new </code></pre> <p>This take me to a form with the following url:</p> <pre><code> http://localhost:3000/households/5/visits/new </code></pre> <p>I Have a simple form set up at this view as so:</p> <pre><code>= simple_form_for [household, visit], url: new_household_visit_path do |f| %h2 Household: #{household.name} </code></pre> <p>Now when I fill in the form and try to save with a submit I get:</p> <pre><code> No route matches [POST] "/households/5/visits/new" </code></pre> <p>Now I did notice that in Rake Routes I have a GET but not a POST but I am still not sure what my problem is?</p> <p>Routes.rb shows:</p> <pre><code> resources :households do resources :visits resources :neighbors end </code></pre> <p>I changed my simple form call to:</p> <pre><code>= simple_form_for [household, visit], url: household_visits_path do |f| </code></pre> <p>I am creating my form but on saving I get the error:</p> <pre><code>Required parameter missing: household </code></pre> <p>the log shows: </p> <pre><code>Started POST "/households/8/visits" for 127.0.0.1 at 2013-06-22 07:58:34 -0400 Processing by VisitsController#create as HTML Parameters: {"utf8"=&gt;"✓", "authenticity_token"=&gt;"HCivpI4SLQTzj2VlwibssNEw/o69jIt4J54/hjVPgJ4=", "visit"=&gt;{"visited_on(1i)"=&gt;"2013", "visited_on(3i)"=&gt;"22", "visited_on(2i)"=&gt;"6", "neighbor_id"=&gt;"46", "starch"=&gt;"Beans", "cereal"=&gt;"", "option1"=&gt;"", "items_received"=&gt;"", "notes"=&gt;""}, "commit"=&gt;"Create Visit", "household_id"=&gt;"8"} User Load (0.4ms) SELECT "users".* FROM "users" WHERE "users"."id" = 1 LIMIT 1 (0.2ms) BEGIN Neighbor Load (0.8ms) SELECT "neighbors".* FROM "neighbors" WHERE "neighbors"."id" = 46 ORDER BY last_name ASC LIMIT 1 (0.2ms) ROLLBACK Rendered visits/_new.html.haml (129.7ms) Rendered visits/new.html.haml within layouts/application (136.2ms) Rendered text template (0.0ms) Completed 400 Bad Request in 1126ms (Views: 7.7ms | ActiveRecord: 0.0ms) </code></pre> <p>I believe I am getting close </p>
    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.
 

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