Krafalski / ConsiderWater

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

Route Rebuild issue: Breath/Colors/Esque #47

Closed Krafalski closed 8 years ago

Krafalski commented 8 years ago

When a user is NOT logged in the links to Breath Colors and Esque in the 'Menu' (application.html.erb) work fine. When a user is logged in, they can access their journal but cannot access Breath Colors Esque: ActionController::UrlGenerationError in Breaths#index Showing /Users/karolinrafalski/dev/considerwater/consider_water_app/app/views/layouts/application.html.erb where line #18 raised:

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

  <div class="menu">
    <% if session[:current_user_id] %>
      <%= link_to "Journal", user_journal_entries_path(@user) %>
      <%= link_to "Mood", user_mood_ratings_path(@user) %>
    <% end %>
    <%= link_to "Breath", breaths_path %>

note: link_to "Journal" is highlighted

not sure why :user_id is nil in this case, but works in other places?

Krafalski commented 8 years ago

What I've tried to to: Move the links in and out of the if statement. Remove the if statement. Copy paste and google the exact message. Comb through the files and try to make sure that things are as correct I know how to make them.

Krafalski commented 8 years ago

needed to add

  def index
    current_user
  end

to controllers of breath, esque and colors

OR

in application.html.erb change

<%= link_to "Mood", user_mood_ratings_path(@user) %>

to

<%= link_to "Mood", user_mood_ratings_path(session[:current_user_id]) %>

the latter solution was chosen

Thanks Colin!