-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding functionality for ratings and reviews
- Loading branch information
1 parent
709734e
commit effae74
Showing
6 changed files
with
63 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
class RatingsController < ApplicationController | ||
def create_rating | ||
if !session[:user] | ||
redirect_to login_path | ||
return | ||
end | ||
|
||
@item = Item.find(params[:item_id]) # Ensure :item_id is passed correctly | ||
@rating = @item.ratings.build(rating_params) | ||
@rating.user_id = session[:user]["id"] | ||
|
||
if @rating.save | ||
redirect_to item_path(@item), notice: "Successfully added rating" | ||
else | ||
redirect_to item_path(@item), alert: "Could not create review" | ||
end | ||
end | ||
|
||
private | ||
|
||
def rating_params | ||
params.require(:rating).permit(:score, :comment) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters