Reputation: 3564
I was wondering if there's a good way to DRY this up.
if session[:working_post].nil?
@post = Post.new
else
@post = Post.new(session[:working_post])
session[:working_post] = nil
end
Maybe something like
@post = Post.new(||= session[:working_post])
Is there anything like that?
Upvotes: 0
Views: 76
Reputation: 11921
If session[:working_post]
is a hash you could do this:
@post = Post.new(session[:working_post] || {})
Upvotes: 1
Reputation: 125
Would this work?
@post = Post.new(session.delete(:working_post) || {})
Upvotes: 5