Advertisement
Guest User

Untitled

a guest
Apr 17th, 2014
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.54 KB | None | 0 0
  1. When(/^I select a student$/) do
  2. click_on "#{@student.first_name} #{@student.last_name}"
  3. end
  4.  
  5. Then(/^I should see their information$/) do
  6. expect(page).to have_content(@student.first_name)
  7. end
  8.  
  9. Scenario: See Individual Student Page
  10. Given I am logged in as a flatiron employee
  11. When I visit the students page
  12. And I select a student
  13. Then I should see their information
  14.  
  15. class CoursesController < ApplicationController
  16. def index
  17. @courses = Course.all
  18. end
  19.  
  20. def new
  21. @course = Course.new
  22. end
  23.  
  24. def create
  25. @course = Course.new(course_params)
  26. if @course.save
  27. flash[:notice] = "Course has successfully been saved."
  28. redirect_to course_path(@course)
  29. else
  30. flash[:notice] = "Error! Course was not successfully saved."
  31. redirect to new_course_path
  32. end
  33. end
  34.  
  35. def show
  36. @course = Course.find(params[:id])
  37. end
  38.  
  39. private
  40.  
  41. def course_params
  42. params.require(:course).permit(:name)
  43. end
  44. end
  45.  
  46. class StudentsController < ApplicationController
  47. before_filter :set_student, only: [:show, :edit, :update, :destroy]
  48.  
  49. def index
  50. @students = Student.all
  51. end
  52.  
  53. def show
  54. end
  55.  
  56. def new
  57. @student = Student.new
  58. end
  59.  
  60. def edit
  61. end
  62.  
  63. def create
  64. @student = Student.new(student_params)
  65. if @student.save
  66. flash[:notice] = "Student form successfully submitted."
  67. redirect_to students_path
  68. else
  69. flash[:error] = "Unable to process your request."
  70. render :new
  71. end
  72. end
  73.  
  74. def update
  75. Student.update(@student, student_params)
  76. redirect_to student_path(@student)
  77. end
  78.  
  79. def destroy
  80. @student.destroy
  81. redirect_to courses_path
  82. end
  83.  
  84. private
  85.  
  86. def set_student
  87. @student = Student.find(params[:id])
  88. end
  89.  
  90. def student_params
  91. params.require(:student).permit(removed_attributes)
  92. end
  93. end
  94.  
  95. Registrar::Application.routes.draw do
  96.  
  97. resources :courses do
  98. resources :students, controller: :courses_students, only: [:new, :create, :show]
  99. end
  100.  
  101. resources :students
  102.  
  103. devise_for :users, :path_names => { sign_in: 'login', sign_out: 'logout' }, :controllers => {
  104. :omniauth_callbacks => "users/omniauth_callbacks",
  105. :sessions => "sessions"
  106. }
  107.  
  108. root 'pages#landing'
  109. end
  110.  
  111. <br><br>
  112. <%= @student.first_name %>
  113. <%= @student.last_name %><br>
  114. <br>
  115. <%= link_to "Back to Course", course_path(@student.course) %>
  116. <%= link_to "Students", students_path %>
  117. <br>
  118.  
  119. <br><br>
  120. <% @students.each do |student| %>
  121. <%= link_to "#{student.first_name} #{student.last_name}", student_path(student) %><br>
  122. <% end %>
  123. <br>
  124. <%= link_to "Landing Page", root_path %>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement