ruby on rails - Couldn't find Timetable with 'id'=clas -
generated timetable scaffold. later created new action "clas" in 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 action "clas". need pass select option values params controller
clas.html.erb
<% form_for @classtimetable, :url => clas_timetables_path, :html => { :method => :post} |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 |class_timetable| %> <%= class_timetable.day %> <% end %>
routes.rb
resources :timetables member 'clas' end end
i need day class in clas.html.erb page. done selecting class dropdown , submit. value should passed in params when click submit. don't know how fix it. ideas?
add controller in form_for
tag,
<% form_for @classtimetable, :url => { :controller => "your-controller-name", :action => :clas } |f| %>
or can directly write this,
<% form_for @classtimetable, :url => clas_timetables_path, :html => { :method => :post} |f| %>
change before_action
like,
before_action :set_timetable, only: [:show, :edit, :update, :destroy, :clas]
you change collection
member
, pass id
resources :timetables member 'clas' end end
Comments
Post a Comment