Created
May 13, 2018 14:25
-
-
Save CodePint/a3d86e6dbb14d884836d404f4093ede4 to your computer and use it in GitHub Desktop.
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
<h1> Add a route to this gym </h1> | |
<br> | |
<%= form_for :route, url: { action: "create" }, method: 'post' do |f| %> | |
<div class="field"> | |
<%= f.label :route_identifier %><br> | |
<%= f.text_field :route_identifier %> | |
</div> | |
<div class="field"> | |
<%= f.label :grade %><br> | |
<%= f.text_field :grade %> | |
</div> | |
<div class="field"> | |
<%= f.label :route_setter_comments %><br> | |
<%= f.text_field :route_setter_comments %> | |
</div> | |
<div class="actions"> | |
<%= f.submit "submit" %> | |
</div> | |
<% 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
def new | |
@route = Route.new | |
@gym = Gym.find(params[:gym_id]) | |
end | |
def create | |
if current_user.route_setter | |
#binding.pry | |
@gym = Gym.find(params[:gym_id]) | |
@route = @gym.route.new(route_params) | |
if @route.save | |
puts "saved" | |
flash[:success]="New route #{@route.identifier} successfully added." | |
redirect_to '/' | |
end | |
else | |
flash[:error]="you do not have correct permmisions to do this, you are not a route setter" | |
puts "not saved" | |
render :new | |
end | |
end | |
def route_params | |
params.require(:route).permit(:identifier, :route_setter_comments, :grade) | |
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 is auto-generated from the current state of the database. Instead | |
# of editing this file, please use the migrations feature of Active Record to | |
# incrementally modify your database, and then regenerate this schema definition. | |
# | |
# Note that this schema.rb definition is the authoritative source for your | |
# database schema. If you need to create the application database on another | |
# system, you should be using db:schema:load, not running all the migrations | |
# from scratch. The latter is a flawed and unsustainable approach (the more migrations | |
# you'll amass, the slower it'll run and the greater likelihood for issues). | |
# | |
# It's strongly recommended that you check this file into your version control system. | |
ActiveRecord::Schema.define(version: 20180502150841) do | |
create_table "climbs", force: :cascade do |t| | |
t.integer "comment_id" | |
t.integer "user_id" | |
t.integer "route_id" | |
t.text "climb_comment" | |
t.boolean "completed" | |
t.string "completion_type" | |
t.datetime "completed_at" | |
t.integer "attempt_count" | |
t.integer "completed_count" | |
t.integer "grade_rating" | |
t.integer "enjoy_rating" | |
t.datetime "created_at", null: false | |
t.datetime "updated_at", null: false | |
t.index ["comment_id"], name: "index_climbs_on_comment_id" | |
t.index ["route_id"], name: "index_climbs_on_route_id" | |
t.index ["user_id"], name: "index_climbs_on_user_id" | |
end | |
create_table "comments", force: :cascade do |t| | |
t.integer "climb_id" | |
t.integer "user_id" | |
t.text "text" | |
t.datetime "created_at", null: false | |
t.datetime "updated_at", null: false | |
t.index ["climb_id"], name: "index_comments_on_climb_id" | |
t.index ["user_id"], name: "index_comments_on_user_id" | |
end | |
create_table "gyms", force: :cascade do |t| | |
t.integer "routes_id" | |
t.string "gym_name", null: false | |
t.text "about" | |
t.string "address" | |
t.string "email" | |
t.datetime "created_at", null: false | |
t.datetime "updated_at", null: false | |
t.string "route_setter_list" | |
t.string "gym_owner_list" | |
t.index ["routes_id"], name: "index_gyms_on_routes_id" | |
end | |
create_table "memberships", force: :cascade do |t| | |
t.integer "user_id" | |
t.integer "gym_id" | |
t.boolean "route_setter" | |
t.boolean "gym_owner" | |
t.boolean "climber" | |
t.datetime "created_at", null: false | |
t.datetime "updated_at", null: false | |
t.index ["gym_id"], name: "index_memberships_on_gym_id" | |
t.index ["user_id"], name: "index_memberships_on_user_id" | |
end | |
create_table "routes", force: :cascade do |t| | |
t.integer "user_id" | |
t.integer "gym_id" | |
t.integer "climbs_id" | |
t.integer "grade" | |
t.datetime "date_set" | |
t.datetime "date_removed" | |
t.datetime "created_at", null: false | |
t.datetime "updated_at", null: false | |
t.index ["climbs_id"], name: "index_routes_on_climbs_id" | |
t.index ["gym_id"], name: "index_routes_on_gym_id" | |
t.index ["user_id"], name: "index_routes_on_user_id" | |
end | |
create_table "users", force: :cascade do |t| | |
t.string "first_name", null: false | |
t.string "last_name", null: false | |
t.string "user_name", null: false | |
t.string "email", default: "", null: false | |
t.string "encrypted_password", default: "", null: false | |
t.string "reset_password_token" | |
t.datetime "reset_password_sent_at" | |
t.datetime "remember_created_at" | |
t.integer "sign_in_count", default: 0, null: false | |
t.datetime "current_sign_in_at" | |
t.datetime "last_sign_in_at" | |
t.string "current_sign_in_ip" | |
t.string "last_sign_in_ip" | |
t.boolean "climber", default: true | |
t.boolean "route_setter", default: false | |
t.boolean "gym_owner", default: false | |
t.integer "comment_id" | |
t.integer "route_id" | |
t.integer "climb_id" | |
t.datetime "created_at", null: false | |
t.datetime "updated_at", null: false | |
t.index ["climb_id"], name: "index_users_on_climb_id" | |
t.index ["comment_id"], name: "index_users_on_comment_id" | |
t.index ["email"], name: "index_users_on_email", unique: true | |
t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true | |
t.index ["route_id"], name: "index_users_on_route_id" | |
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
http://127.0.0.1:3000/routes/new?gym=1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Error: Couldn't find Gym with 'id'=
how do i pass the params of the gym id, between new and create