Skip to content

Commit 94e29df

Browse files
committed
Allow viewing home without being logged in
1 parent a926748 commit 94e29df

File tree

2 files changed

+23
-8
lines changed

2 files changed

+23
-8
lines changed

app/controllers/homes_controller.rb

+3-1
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,16 @@ class HomesController < ApplicationController
66

77
before_action :store_location, only: %i[index show new edit]
88

9+
skip_before_action :authenticate_user!, only: %i[show refresh_listing]
10+
911
def index
1012
filter_disabled = params[:disabled] == 'true'
1113
@homes = @hunt.homes.where(disabled: filter_disabled).includes(:ratings)
1214
end
1315

1416
def show
1517
@ratings = Rating.aspects.keys.map do |aspect|
16-
current_user.ratings.find_or_initialize_by(home: @home, aspect:)
18+
Rating.find_or_initialize_by(user: current_user, home: @home, aspect:)
1719
end
1820

1921
@others_ratings = @home.ratings.where.not(user: current_user).includes(:user).to_a

app/views/homes/show.html.erb

+20-7
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@
1919
</p>
2020
</div>
2121
<div class="col-sm-4 text-right">
22-
<%= link_to 'Edit', edit_hunt_home_path(@hunt, @home), class: 'btn btn-warning' %>
22+
<% if user_signed_in? %>
23+
<%= link_to 'Edit', edit_hunt_home_path(@hunt, @home), class: 'btn btn-warning' %>
24+
<% else %>
25+
<%= link_to 'Log in', new_session_path('user'), class: 'btn btn-warning' %>
26+
<% end %>
2327
<% if @home.disabled? %>
2428
<%= link_to 'Restore',
2529
restore_hunt_home_path(@hunt, @home),
@@ -32,11 +36,13 @@
3236
method: :patch,
3337
class: 'btn btn-info' %>
3438
<% end %>
35-
<%= link_to 'Archive',
36-
hunt_home_path(@hunt, @home),
37-
method: :delete,
38-
data: { confirm: 'Really archive this home?' },
39-
class: 'btn btn-danger' %>
39+
<% if user_signed_in? %>
40+
<%= link_to 'Archive',
41+
hunt_home_path(@hunt, @home),
42+
method: :delete,
43+
data: { confirm: 'Really archive this home?' },
44+
class: 'btn btn-danger' %>
45+
<% end %>
4046
<% end %>
4147

4248
<h3><%= @home.price_display %></h3>
@@ -64,7 +70,14 @@
6470
</div>
6571
<div class="col-12 col-lg-4">
6672
<%= render 'comments/list', comments: @home.comments %>
67-
<%= render 'comments/form', comment: @home.comments.new %>
73+
<% if user_signed_in? %>
74+
<%= render 'comments/form', comment: @home.comments.new %>
75+
<% else %>
76+
<p>
77+
<%= link_to 'Log in', new_session_path('user') %>
78+
to leave a comment or rating.
79+
</p>
80+
<% end %>
6881

6982
<% @ratings.each do |rating| %>
7083
<br>

0 commit comments

Comments
 (0)