I am having a route issue with my Sinatra application. I am using ActiveRecords btw. When I enter information on a form I have it set up to the target post method but the redirect is not working when it hits that post method. Instead it keeps looping back to the form I was just on.
get '/players/new' do
if logged_in?
erb :'players/add_player'
else
redirect '/login'
end
end
Here is the ERB file that it renders
<h2>Add a member to the team</h2>
<form method ='/players' method='POST'>
<label for = 'name'>Name:</label>
<input type = 'text' name = 'name'id = 'name'><br>
<label for = 'position'>Position:</label>
<input type = 'text' name = 'position' id = 'position'><br>
<label for = 'height'>Height:</label>
<input type = 'text' name = 'name' id = 'name'><br>
<label for = 'weight'>Weight:</label>
<input type = 'text' name = 'weight' id = 'weight'><br>
<input type = 'submit' value = 'Join The Team'>
</form>
And here is the post method it supposed to send information to
post "/players" do
if params == ""
redirect to '/players/new'
else
@player = Player.create(params)
redirect to "/players/#{@player.id}"
end
end
But keeps looping back to add_player file. Where am I going wrong.
Here is the get request its supposed to redirect to
get "/players/:id" do
@player = Player.find(params[:id])
erb :"players/show_player"
end
My cohort lead just looked at it, and it's one little syntax error. I fixed it and it worked. I forgot to change method ='/players' to action = '/players'
at the top of my form. It was a little tricky to cathc in all the running around.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.