jeudi 4 juin 2015

Couldn't find Timetable with 'id'=clas

Generated a timetable scaffold. Then later created a new action "clas" in my timetables_controller.rb.

timetables_controller.rb

class TimetablesController < ApplicationController
before_action :set_timetable, only: [:show, :edit, :update, :destroy, :clas]
def clas
  @classtimetable = Timetable.where(params[:clas])
end

//other actions

def set_timetable
  @timetable = Timetable.find(params[:id])
end

def timetable_params
  params.require(:timetable).permit(:day, :clas, :one_teacher, :one_sub, :two_teacher, :two_sub, :three_teacher, :three_sub, :four_teacher, :four_sub, :five_teacher, :five_sub, :six_teacher, :six_sub, :seven_teacher, :seven_sub, :eight_teacher, :eight_sub)
end
end

Created form_for to the action "clas". Need to pass the select option values as params to the controller

clas.html.erb

<% form_for @classtimetable, :url => clas_timetables_path, :html => { :method => :post} do |f| %>
<div class="field">
  <%= f.label "Select class" %>
  <% values = ["1c", "2c", "3c", "4d", "5i"] %>
  <%= f.select :clas, options_for_select(values) %>
</div>
<div class="actions">
  <%= f.submit "Submit"%>
</div>
<% end %>

<% @classtimetable.each do |class_timetable| %>
<%= class_timetable.day %>
<% end %>

routes.rb

resources :timetables do
member do
  get 'clas'
end
end

I need to get all the day for the class in my clas.html.erb page. Which is done by selecting the class from dropdown and submit. The value should be passed in params when i click submit. don't know how to fix it. Any ideas?

Aucun commentaire:

Enregistrer un commentaire