I have a simple web app built on rails called wishlist. The logic of the app is as follows:
- User Enters the homepage
- User can either start a new wishlist || view his wishlists
- When the user clicks on start a new wishlist the user is brought to a separate view where he enters the name of the wishlist & submits the name.
- After the wishlist is created, he is brought to another view which includes a call-to-action called 'DONE' & the entire URL of the website - the URL includes the #show path of the wishlist that has just been created.
- When the user clicks on 'DONE', he is brought to the index view of all the wishlists where he can view each & every wishlist as well as click on a specific wishlist & view it separately in the #show view.
My problem is that the entire URL of the website gets rendered normally in step No. 4 - when the user has just created a wishlist. But when the user views a specific wishlist via the #show path, the entire HTTP path of the URL doesn't get rendered normally & the only thing that is returned is the #show path (even though I'm using the same lines of code in the both places).
Here is a video of my app to exemplify what I mean: https://www.loom.com/share/f6f9a64b875c4a5ea69e65c1b1cdc0bc
And this where I'm rendering the entire HTTP path of my website sucessfully:
<h1>Wishlist created!</h1>
<p>The URL for your wishlist is:</p>
<p><%= link_to @show_url, wishlist_path(@wishlist) %></p>
<p>Use this URL to view your wishlist.</p>
<%= link_to "Done", wishlists_path %>
And this where I'm unable to render the entire HTTP path of my website (even though I'm using the exact link_to method):
<p style="color: green"><%= notice %></p>
<%= render @wishlist %>
<%= render "form", wishlist: @wishlist %>
<br>
<p><%= link_to @show_url, wishlist_path(@wishlist) %></p>
<div>
<%= button_to "Delete this wishlist", @wishlist, method: :delete %>
<%= link_to "Back to wishlists", wishlists_path %>
</div>
This is my wishlist controller if it helps:
class WishlistsController < ApplicationController
before_action :set_wishlist, only: %i[ show edit update destroy ]
# GET /home
def home
end
# GET /wishlists
def index
@wishlists = Wishlist.all
end
# GET /wishlists/1
def show
@wishlist = Wishlist.find(params[:id])
end
# GET /wishlists/new
def new
@wishlist = Wishlist.new
end
# GET /wishlists/1/edit
def edit
end
# POST /wishlists
def create
@wishlist = Wishlist.new(wishlist_params)
if @wishlist.save
@show_url = url_for(controller: 'wishlists', action: 'show', id: @wishlist.id, only_path: false)
render :show_url
else
render :new, status: :unprocessable_entity
end
end
# PATCH/PUT /wishlists/1
def update
if @wishlist.update(wishlist_params)
redirect_to @wishlist, notice: "Wishlist was successfully updated."
else
render :edit, status: :unprocessable_entity
end
end
# DELETE /wishlists/1
def destroy
@wishlist.destroy
redirect_to wishlists_url, notice: "Wishlist was successfully destroyed."
end
private
# Use callbacks to share common setup or constraints between actions.
def set_wishlist
@wishlist = Wishlist.find(params[:id])
end
# Only allow a list of trusted parameters through.
def wishlist_params
params.require(:wishlist).permit(:name, :wishlist_link)
end
end