learn-co-curriculum / playlister-sinatra

Other
0 stars 387 forks source link

Rack::Flash causing errors - change to Sinatra::Flash #60

Closed marielfrank closed 6 years ago

marielfrank commented 7 years ago

Rack::Flash was causing the following error on this lab:

/home/marielfrank/playlister-sinatra-v-000/app/controllers/application_controller.rb:7:in '<class:ApplicationController>': uninitialized constant Rack::Flash (NameError)

Switching to Sinatra::Flash, the issues were quickly resolved.

For the ERB,, it would be necessary to change this code: <% if flash.has?(:message) %> <%= flash[:message] %> <% end %>

to:

<% if !!flash[:message] %> <%= flash[:message] %> <% end %>

DakotaLMartinez commented 7 years ago

@gj this works for me. I've had a lot of students have issues with rack flash in Sinatra. And, a lot that don't... This seems like it could be a good alternative, though.

ThePeej commented 6 years ago

Was running into the same issue, and this helped. However, I also was having trouble writing to the flash hash. Everytime I would do flash[:message] = "Successfully created song.", the flash hash would not accept the key or value. So when the flash[:message] was called in the songs/show.erb file, it was still an empty flash, and the message would not ever pop up to pass the spec/test. I looked through the Sinatra Flash documentation a bit, and I eventually got it to work using the 'flash.next' hash.

Just to clarify, in the post '/songs' & patch '/songs/:slug' routes, I used the following code

flash.next[:message] = "Successfully updated song."

This worked, and I still kept the songs/show.erb file the same as the suggestion above (still using flash[:message] as opposed to having to use flash.now[:message] or flash.next[:message])

DanielSeehausen commented 6 years ago

Hi all -- thank you for bringing this to our attention. After following the readme (specifically the portion on rack-flash3), I was unable to reproduce the issue with the following code in the solution branch: <% if flash.has?(:message) %> <%= flash[:message] %> <% end %>

I'm having difficulty reproducing the issue, so I'm going to close it for now.

If you can provide further detail about the steps required to reproduce the issue and any additional relevant information about your development environment (local or IDE), I'd be happy to take a second look!

As always, thanks for contributing! 💙