create a hash of favorite details and reuse it;
move redirect_back out of conditional scope
This commit is contained in:
parent
5bb0bae858
commit
9dcb2994e1
@ -27,14 +27,17 @@ class Crawlers::PeopleCrawlerController < Crawlers::TissCrawlerController
|
|||||||
@person = TissCrawler.get_details(params)
|
@person = TissCrawler.get_details(params)
|
||||||
|
|
||||||
# create stores the object to the db after creation
|
# create stores the object to the db after creation
|
||||||
if FavoritePerson.create(tiss_id: @person['tiss_id'], first_name: @person['first_name'], last_name: @person['last_name'], picture_uri: @person['picture_uri']).valid?
|
favorite_hash = { tiss_id: @person['tiss_id'],
|
||||||
FavoritePerson.create(tiss_id: @person['tiss_id'], first_name: @person['first_name'], last_name: @person['last_name'], picture_uri: @person['picture_uri'])
|
first_name: @person['first_name'],
|
||||||
flash[:alert] = "Person added to your favorites!"
|
last_name: @person['last_name'],
|
||||||
redirect_back(fallback_location: search)
|
picture_uri: @person['picture_uri'] }
|
||||||
|
if FavoritePerson.create(favorite_hash).valid?
|
||||||
|
FavoritePerson.create(favorite_hash)
|
||||||
|
flash[:alert] = 'Person added to your favorites!'
|
||||||
else
|
else
|
||||||
flash[:alert] = "Person is already favorited!"
|
flash[:alert] = 'Person is already favorited!'
|
||||||
redirect_back(fallback_location: search)
|
|
||||||
end
|
end
|
||||||
|
redirect_back(fallback_location: search)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user