Skip to content

Commit

Permalink
Adding Basic Welcome & Contact Us Pages with Links
Browse files Browse the repository at this point in the history
  • Loading branch information
LiorKGOW committed Dec 21, 2022
1 parent f069609 commit 1a7a9ba
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 1 deletion.
39 changes: 39 additions & 0 deletions app/controllers/guitars_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,45 @@ def index
def guitar_gallery; end

def welcome_page; end

def contact
# redirect_to(:action => 'contact_us')

param = params['country']
@phone_number = nil

if param == 'us' || param == 'ca'
@phone_number = '(800) 555-6789'
elsif param == 'uk'
@phone_number = '(020) 7946-1234'
else
@phone_number = '+972 (052) 654-3210'
end

##############################################
# another option:

if ['us','ca'].include?(params[:country])
@phone_number = '(800) 555-6789'
elsif params[:country] == 'uk'
@phone_number = '(020) 7946-1234'
else
@phone_number = '+972 (052) 654-3210'
end

##############################################
# another option: (Rubocop)

@phone_number = if %w[us ca].include?(params[:country])
'(800) 555-6789'
elsif params[:country] == 'uk'
'(020) 7946-1234'
else
'+972 (052) 654-3210'
end

render('contact_us')
end
end

# rubocop:enable Metrics/MethodLength
10 changes: 10 additions & 0 deletions app/views/guitars/contact_us.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<h1>Contact</h1>

<p>We are always happy to hear from our customers !</p>

<p>Phone: <%= @phone_number %></p>

<p>Press: <a href="mailto:[email protected]">[email protected]</a></p>
<p>Or Press: <%= mail_to('[email protected]') %></p>

<%= link_to('Go to Welcome Page', {:action => 'welcome_page'}) %>
6 changes: 5 additions & 1 deletion app/views/guitars/welcome_page.html.erb
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
<h1>Guitars#welcomePage</h1>
<h1>Welcome to My Guitar Store</h1>

<%= link_to('Go to Contact Us (us)', {:action => 'contact', :country => 'us'}) %><br />
<%= link_to('Go to Contact Us (uk)', {:action => 'contact', :country => 'uk'}) %><br />
<%= link_to('Go to Contact Us (no query parameter)', {:action => 'contact'}) %>
3 changes: 3 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
get 'guitars/guitar_gallery'
get 'guitars/welcome_page'

# Challenge route:
get 'guitars/contact'

# route to get the mock data:
get '/guitars', to: 'guitars#index'

Expand Down

0 comments on commit 1a7a9ba

Please sign in to comment.