Krafalski / ConsiderWater

A Web App For Anxious People
0 stars 0 forks source link

Route Rebuild issue - mood rating create #48

Closed Krafalski closed 8 years ago

Krafalski commented 8 years ago

user_id has a value in the parameters, but being passed as nil in the route?

Request

Parameters:

{"utf8"=>"✓",
 "authenticity_token"=>"EJ+jiodmrBrJgu+M9UWlHfVrf+y6ESQVOeWFMpYfNEdS0TotjHVrQXm1R3guNba9+9Vl4tIYsCmFjB/wEIHnTA==",
 "mood_rating"=>{"rating"=>"600"},
 "commit"=>"save",
 "user_id"=>"2"}

error:

ActionController::UrlGenerationError in MoodRatingsController#create

No route matches {:action=>"index", :controller=>"mood_ratings", :user_id=>nil} missing required keys: [:user_id]

  def create
    @mood_rating = current_user.mood_ratings.build(mood_rating_params)
    redirect_to user_mood_ratings_path(@mood_rating)
    if @mood_rating.save
      redirect_to user_mood_ratings_path(@mood_rating)
    else
Krafalski commented 8 years ago

.build is an instance but doesn't save. So there is no data being stored in the redirect. Redirect must happen after save (when the data is actually saved in the instance). removed redirect under @mood, left it in the if statement.

Krafalski commented 8 years ago

this is in the chart kick branch (this is where we started working on rebuilding the routes). Will need to merge to dev once the last few rebuild issues are ironed out.