I am new to Ruby on Rails and we have a project called TaskApp.
It that has 2 models: Category, Task.
Category has many tasks and Task belongs to Category.
When I go from tasks index to edit task, I am getting the edit view with blank fields.
Please find relevant codes below.
I am grateful for any advise to get me to resolve this.
routes.rb
Rails.application.routes.draw do
devise_for :users, controllers: { registrations: 'registrations' }
get 'home/index'
root 'home#index'
resources :categories do
resources :tasks
end
end
tasks_controller.rb
class TasksController < ApplicationController
before_action :authenticate_user!
before_action :set_category, except: %i[index edit]
before_action :set_task, only: %i[show update destroy]
def index
#tasks = Task.where(user_id: current_user.id, deadline: Time.zone.now.beginning_of_day..Time.zone.now.end_of_day).order(priority: :asc)
end
def new
#task = #category.tasks.build
end
def show
end
def create
#task = #category.tasks.create(task_params.merge(user_id: current_user.id))
respond_to do |format|
if #task.save
format.html { redirect_to #task.category, notice: "Task was successfully created." }
format.json { render :show, status: :created, location: #task.category }
else
format.html { redirect_to #task.category, notice: "Invalid inputs." }
format.json { render json: #task.errors, status: :unprocessable_entity }
end
end
end
def edit
#category = Category.find(params[:category_id])
#task = #category.tasks.find(params[:id])
end
def update
respond_to do |format|
if #task.update(task_params)
format.html { redirect_to #task.category, notice: 'Task was successfully updated.' }
format.json { render :show, status: :ok, location: #task }
else
format.html { render :edit }
format.json { render json: #task.errors, status: :unprocessable_entity }
end
end
end
def destroy
#task.destroy
respond_to do |format|
format.html { redirect_to #task.category, notice: 'Task was successfully destroyed.' }
format.json { head :no_content }
end
end
private
def set_category
#category = Category.find(params[:category_id])
end
def set_task
#task = #category.tasks.find(params[:id])
end
def task_params
params.require(:task).permit(:name, :description, :priority, :deadline, :completed, :user_id, :category_id)
end
end
.../tasks/views/edit.html.erb
<div>
<table>
<thead>
<tr>
<th>Name</th>
<th>Description</th>
<th>Priority</th>
<th>Deadline</th>
<th>Completed</th>
<th>Action</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<% #category.tasks.each do |task| %>
<% if task.user_id == current_user.id %>
<tr>
<td><%= link_to task.name, [task.category, task] %></td>
<td><%= task.description %></td>
<td><%= task.priority %></td>
<td><%= task.deadline.strftime("%d %b %Y") %></td>
<td><%= task.completed %></td>
<td><%= link_to 'Edit', edit_category_task_path(task.category, task) %></td>
<td><%= link_to 'Delete', [task.category, task],
method: :delete,
data: { confirm: 'Are you sure?' } %>
</td>
</tr>
<% end %>
<% end %>
</tbody>
</table>
</div>
Related
I want to set a reservation based on user_id and trip_id . but i dont know how to . I tried to make a form in trips/show
What i want is to see the full list of trips and select one and the form below should save the user_id and trip_id in databse. Idk if i can send data like this because i wrote the form in trips which has his own model of Trip.
Can someone explain how has_many :through concept work. The problem is that idk if i can make another controller to save ids or i can do it in trip controllers. please help
<h1>Trips</h1>
<table class="table ">
<thead class="thead-dark">
<tr>
<th>Locatie</th>
<th>Descriere</th>
<th colspan="3"></th>
</tr>
</thead>
<%= Current.user.admin %>
<% if Current.user.admin == true %>
<tbody>
<% #trips.each do |trip| %>
<tr>
<td><%= trip.locatie %></td>
<td><%= trip.descriere %></td>
<td class="text-center"><%= link_to 'Select', trip , class: "btn btn-secondary "%></td>
<td class="text-center"><%= link_to 'Edit', edit_trip_path(trip) ,class: "btn btn-secondary " %></td>
<td class="text-center"><%= link_to 'Destroy', trip, method: :delete, data: { confirm: 'Are you sure?' } ,class: "btn btn-secondary "%></td>
</tr>
<% end %>
</tbody>
<% else %>
<tbody>
<% #trips.each do |trip| %>
<tr>
<td><%= trip.locatie %></td>
<td><%= trip.descriere %></td>
<td class="text-center"><%= link_to 'Select', trip , class: "btn btn-secondary "%></td>
</tr>
<% end %>
</tbody>
<% end %>
</table>
<br>
<%= link_to 'New Trip', new_trip_path ,class:"btn btn-secondary"%>
<p>
<strong>Locatie:</strong>
<%= #trip.locatie %>
</p>
<p>
<strong>Descriere:</strong>
<%= #trip.descriere %>
</p>
<%= #trip.id %>
<%= Current.user.id %>
<br/>
<%= form_with model: #reservation, local: true , url: save_reservation_path do |form| %>
<%= form.text_field :user_id , value: #trip.id %>
<%= form.text_field :trip_id , value: Current.user.id%>
<%= form.submit %>
<% end %>
<%= link_to 'Back', trips_path ,class: "btn btn-secondary "%>
Trip controller
class TripsController < ApplicationController
before_action :set_trip, only: %i[ show edit update destroy ]
# GET /trips or /trips.json
def index
#trips = Trip.all
end
# GET /trips/1 or /trips/1.json
def show
end
# GET /trips/new
def new
#trip = Trip.new
end
# GET /trips/1/edit
def edit
end
# POST /trips or /trips.json
def create
#trip = Trip.new(trip_params)
respond_to do |format|
if #trip.save
format.html { redirect_to trip_url(#trip), notice: "Trip was successfully created." }
format.json { render :show, status: :created, location: #trip }
else
format.html { render :new, status: :unprocessable_entity }
format.json { render json: #trip.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /trips/1 or /trips/1.json
def update
respond_to do |format|
if #trip.update(trip_params)
format.html { redirect_to trip_url(#trip), notice: "Trip was successfully updated." }
format.json { render :show, status: :ok, location: #trip }
else
format.html { render :edit, status: :unprocessable_entity }
format.json { render json: #trip.errors, status: :unprocessable_entity }
end
end
end
# DELETE /trips/1 or /trips/1.json
def destroy
#trip.destroy
respond_to do |format|
format.html { redirect_to trips_url, notice: "Trip was successfully destroyed." }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_trip
#trip = Trip.find(params[:id])
end
# Only allow a list of trusted parameters through.
def trip_params
params.require(:trip).permit(:locatie, :descriere)
end
end
Reservation controller
class ReservationsController < ApplicationController
# GET /reservations or /reservations.json
def index
#reservations = Reservation.all
end
# GET /reservations/1 or /reservations/1.json
def show
#reservations = Reservation.all
end
# GET /reservations/new
def new
#reservation = Reservation.new
end
# GET /reservations/1/edit
def edit
end
# POST /reservations or /reservations.json
def create
#reservation = Reservation.new(reservation_params)
respond_to do |format|
if #reservation.save
format.html { redirect_to reservation_url(#reservation), notice: "Reservation was successfully created." }
format.json { render :show, status: :created, location: #reservation }
else
format.html { render :new, status: :unprocessable_entity }
format.json { render json: #reservation.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /reservations/1 or /reservations/1.json
def update
respond_to do |format|
if #reservation.update(reservation_params)
format.html { redirect_to reservation_url(#reservation), notice: "Reservation was successfully updated." }
format.json { render :show, status: :ok, location: #reservation }
else
format.html { render :edit, status: :unprocessable_entity }
format.json { render json: #reservation.errors, status: :unprocessable_entity }
end
end
end
# DELETE /reservations/1 or /reservations/1.json
def destroy
#reservation.destroy
respond_to do |format|
format.html { redirect_to reservations_url, notice: "Reservation was successfully destroyed." }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_reservation
#reservation = Reservation.find(params[:id])
end
# Only allow a list of trusted parameters through.
def reservation_params
params.require(:reservation_params).permit(user_id: [], trip_id: [])
end
end
I am currently getting this error while loading up the homepage. I have only create the first page which I's trying to make the homepage. TweeetsController#index is missing a template for request formats: text/html Below are my codes for the controller, view, and routes. Thank you for any help.
Controller:
class TweeetsController < ApplicationController
before_action :set_tweeet, only: [:show, :edit, :update, :destroy]
# GET /tweeets
# GET /tweeets.json
def index
#tweeets = Tweeet.all
end
# GET /tweeets/1
# GET /tweeets/1.json
def show
end
# GET /tweeets/new
def new
#tweeet = Tweeet.new
end
# GET /tweeets/1/edit
def edit
end
# POST /tweeets
# POST /tweeets.json
def create
#tweeet = Tweeet.new(tweeet_params)
respond_to do |format|
if #tweeet.save
format.html { redirect_to #tweeet, notice: 'Tweeet was successfully created.' }
format.json { render :show, status: :created, location: #tweeet }
else
format.html { render :new }
format.json { render json: #tweeet.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /tweeets/1
# PATCH/PUT /tweeets/1.json
def update
respond_to do |format|
if #tweeet.update(tweeet_params)
format.html { redirect_to #tweeet, notice: 'Tweeet was successfully updated.' }
format.json { render :show, status: :ok, location: #tweeet }
else
format.html { render :edit }
format.json { render json: #tweeet.errors, status: :unprocessable_entity }
end
end
end
# DELETE /tweeets/1
# DELETE /tweeets/1.json
def destroy
#tweeet.destroy
respond_to do |format|
format.html { redirect_to tweeets_url, notice: 'Tweeet was successfully destroyed.' }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_tweeet
#tweeet = Tweeet.find(params[:id])
end
# Only allow a list of trusted parameters through.
def tweeet_params
params.require(:tweeet).permit(:tweeet)
end
end
view:
<p id="notice"><%= notice %></p>
<h1>Tweeets</h1>
<table>
<thead>
<tr>
<th>Tweeet</th>
<th colspan="3"></th>
</tr>
</thead>
<tbody>
<% #tweeets.each do |tweeet| %>
<tr>
<td><%= tweeet.tweeet %></td>
<td><%= link_to 'Show', tweeet %></td>
<td><%= link_to 'Edit', edit_tweeet_path(tweeet) %></td>
<td><%= link_to 'Destroy', tweeet, method: :delete, data: { confirm: 'Are you sure?' } %></td>
</tr>
<% end %>
</tbody>
</table>
<br>
<%= link_to 'New Tweeet', new_tweeet_path %>
routes:
resources :tweeets
# For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html
root "tweeets#index"
end
model:
class Tweeet < ApplicationRecord
end
I am trying to add items to a table in rails but getting the error it the title. It works for me locally but on heroku it gives me this error. I have seen a couple of solution but none seem to work. This is my controller:
require './app/policies/personal_trainer_policy'
class PersonalTrainersController < ApplicationController
before_action :set_personal_trainer, only: [:show, :edit, :update, :destroy]
# GET /personal_trainers
# GET /personal_trainers.json
def index
#personal_trainers = PersonalTrainer.all
end
# GET /personal_trainers/1
# GET /personal_trainers/1.json
def show
end
# GET /personal_trainers/new
def new
#personal_trainer = PersonalTrainer.new
end
# GET /personal_trainers/1/edit
def edit
end
def personal_trainer_policy
#_personal_trainer_policy ||= PersonalTrainerPolicy.new(personal_trainer)
end
# POST /personal_trainers
# POST /personal_trainers.json
def create
#personal_trainer = PersonalTrainer.new(personal_trainer_params)
authorize #personal_trainer
if #personal_trainer.persist
render json: #personal_trainer.record
else
render json: #personal_trainer.errors, status: :unpocessably_entity
end
respond_to do |format|
if #personal_trainer.save
format.html { redirect_to #personal_trainer, notice: 'Personal trainer was successfully created.' }
format.json { render :show, status: :created, location: #personal_trainer }
else
format.html { render :new }
format.json { render json: #personal_trainer.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /personal_trainers/1
# PATCH/PUT /personal_trainers/1.json
def update
authorize #personal_trainer
respond_to do |format|
if #personal_trainer.update(personal_trainer_params)
format.html { redirect_to #personal_trainer, notice: 'Personal trainer was successfully updated.' }
format.json { render :show, status: :ok, location: #personal_trainer }
else
format.html { render :edit }
format.json { render json: #personal_trainer.errors, status: :unprocessable_entity }
end
end
end
# DELETE /personal_trainers/1
# DELETE /personal_trainers/1.json
def destroy
authorize #personal_trainer
#personal_trainer.destroy
respond_to do |format|
format.html { redirect_to personal_trainers_url, notice: 'Personal trainer was successfully destroyed.' }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_personal_trainer
#personal_trainer = PersonalTrainer.find(params[:id])
end
# Only allow a list of trusted parameters through.
def personal_trainer_params
params.require(:personal_trainer).permit(:firstName, :secondName, :desription, :amountOfClients)
end
end
The controller was generated using a scaffold. This is my erb file:
<p id="notice"><%= notice %></p>
<h1 class = "title">Personal Trainers</h1>
<div class = "page-conatiner">
<table class = "table">
<thead>
<%= stylesheet_link_tag 'gym_classes', media: 'all', 'data-turbolinks-track': 'reload' %>
<tr>
<th>First Name</th>
<th>Second Name</th>
<th>Desription</th>
<th>Amount of Clients</th>
<th colspan="3"></th>
</tr>
</thead>
<tbody>
<% #personal_trainers.each do |personal_trainer| %>
<tr>
<td><%= personal_trainer.firstName %></td>
<td><%= personal_trainer.secondName %></td>
<td><%= personal_trainer.desription %></td>
<td><%= personal_trainer.amountOfClients %></td>
<td><%= link_to 'Show', personal_trainer %></td>
<td><%= link_to 'Edit', edit_personal_trainer_path(personal_trainer) %></td>
<td><%= link_to 'Destroy', personal_trainer, method: :delete, data: { confirm: 'Are you sure?' } %></td>
</tr>
<% end %>
</tbody>
</table>
<br>
<% if current_user.admin == true %>
<%= link_to 'New Personal Trainer', new_personal_trainer_path %>
<% end %>
</div>
and this is my model:
class PersonalTrainer < ApplicationRecord
has_many :gym_class_final
has_many :pt_client
end
I have it set so that admins can only create new items using a policy and adding authorise #personal_trainer. I wonder if this has something to do with the error. I just dont understand how it would work locally but not when its deployed. Any suggestions.
persist is not a valid method on an active record object, you're looking for save:
if #personal_trainer.save
render json: #personal_trainer.record
else
render json: #personal_trainer.errors, status: :unpocessably_entity
end
For more information on what methods are available for active record persistence, see https://api.rubyonrails.org/classes/ActiveRecord/Persistence.html (Rails 6)
As a follow up to this earlier question, which has been solved
I have made a beginning with a rails app where I can create Collections. Each Collections is able to have multiple Photos. I can now create these Collections and Photos. But whenever I try to visit /collections/1/photos it has a problem with this line in my photos index
undefined method `photo_path' for #<#<Class:0x007fb8c40f1b38>:0x007fb8c88673a0>
<td><%= link_to 'Show', photo %></td>
photos_controller.rb
class PhotosController < ApplicationController
before_action :set_photo, only: [:show, :edit, :update, :destroy]
# GET /photos
# GET /photos.json
def index
#photos = Photo.all
end
# GET /photos/1
# GET /photos/1.json
def show
end
# GET /photos/new
def new
#photo = Photo.new
end
# GET /photos/1/edit
def edit
end
# POST /photos
# POST /photos.json
def create
#photo = Photo.new(photo_params)
respond_to do |format|
if #photo.save
redirect_to #photo
format.html { redirect_to #photo, notice: 'Photo was successfully created.' }
format.json { render :show, status: :created, location: #photo }
else
format.html { render :new }
format.json { render json: #photo.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /photos/1
# PATCH/PUT /photos/1.json
def update
respond_to do |format|
if #photo.update(photo_params)
format.html { redirect_to #photo, notice: 'Photo was successfully updated.' }
format.json { render :show, status: :ok, location: #photo }
else
format.html { render :edit }
format.json { render json: #photo.errors, status: :unprocessable_entity }
end
end
end
# DELETE /photos/1
# DELETE /photos/1.json
def destroy
#photo.destroy
respond_to do |format|
format.html { redirect_to photos_url, notice: 'Photo was successfully destroyed.' }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_photo
#photo = Photo.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def photo_params
params.require(:photo).permit(:name, :collection_id)
end
end
routes.rb
Rails.application.routes.draw do
resources :collections do
resources :photos
end
end
/photos/index.html
<p id="notice"><%= notice %></p>
<h1>Photos</h1>
<table>
<thead>
<tr>
<th colspan="3"></th>
</tr>
</thead>
<tbody>
<% #photos.each do |photo| %>
<tr>
<td><%= photo.name %></td>
<td><%= link_to 'Show', photo %></td>
<td><%= link_to 'Edit', edit_photo_path(photo) %></td>
<td><%= link_to 'Destroy', photo, method: :delete, data: { confirm: 'Are you sure?' } %></td>
</tr>
<% end %>
</tbody>
</table>
<br>
<%= link_to 'New Photo', new_collection_photo_path %>
collection.rb
class Collection < ApplicationRecord
has_many :photos
end
photo.rb
class Photo < ApplicationRecord
belongs_to :collection
end
I use Rails 5.0.0.1 and ruby 2.3.0
Use this your show and delete link path is wrong
<td><%= link_to 'Show', collection_photo_path(#collection, photo) %></td>
<td><%= link_to 'Edit', edit_collection_photo_path(#collection, photo) %></td>
<td><%= link_to 'Destroy',
collection_photo_path(#collection, photo), method: :delete, data: { confirm: 'Are you sure?' } %></td>
Links should be made this , from controller you should intialize #collection
def index
#collction = Collection.find(params[:collection_id])
#photos = #collction.photos
end
I was trying to show the student name on the submission table but I don't know how to do it. If you can please help me!
Form.rb:
class Form < ActiveRecord::Base
belongs_to :user
has_many :submissions, :dependent => :destroy
has_attached_file :image, styles: { medium: "400x600>" }
validates_attachment_content_type :image, content_type: /\Aimage\/.*\z/
end
Submission.rb:
class Submission < ActiveRecord::Base
belongs_to :form
has_many :submissionstudent
has_many :students, :through => :submissionstudent
end
Student.rb:
class Student < ActiveRecord::Base
has_many :submissionstudent
has_many :submissions, :through => :submissionstudent
end
Joint Table: Submissionstudent:
class Submissionstudent < ActiveRecord::Base
belongs_to :submission
belongs_to :student
end
Show Table:
<h1><%= #form.title %></h1>
<p>
<%= image_tag #form.image.url(:medium) %>
</p>
<table class="table table-responsive table-hover">
<% if user_signed_in? %>
<% if #submissions.blank? %>
<h4>No submission just yet</h4>
<% else %>
<thead>
<th>Conflict</th>
<th>Computer</th>
<th>Extra time</th>
<th>AM or PM</th>
</thead>
<tbody>
<% #submissions.each do |submission| %>
<tr>
<td><%= submission.conflict %></td>
<td><%= submission.computer %></td>
<td><%= submission.extra_time %>%</td>
<td><%= submission.am_pm %></td>
<!-- Need to add Edit, Delete -->
</tr>
<% end %>
</tbody>
<% end %>
<% end %>
</table>
<%= link_to 'New Submission', new_form_submission_path(#form) %>
<br>
<%= link_to 'Edit', edit_form_path(#form) %> |
<%= link_to 'Back', forms_path(#form) %>
Submission Controller:
class SubmissionsController < ApplicationController
before_action :set_submission, only: [:show, :edit, :update, :destroy]
before_action :set_form
# GET /submissions/new
def new
#submission = Submission.new
#all_students = Student.all
#submission_student = #submission.submissionstudent.build
end
# GET /submissions/1/edit
def edit
end
# POST /submissions
# POST /submissions.json
def create
#submission = Submission.new(submission_params)
#submission.form_id = #form.id
respond_to do |format|
if #submission.save
format.html { redirect_to #form, notice: 'Submission was successfully created.' }
format.json { render :show, status: :created, location: #submission }
else
format.html { render :new }
format.json { render json: #submission.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /submissions/1
# PATCH/PUT /submissions/1.json
def update
respond_to do |format|
if #submission.update(submission_params)
format.html { redirect_to #submission, notice: 'Submission was successfully updated.' }
format.json { render :show, status: :ok, location: #submission }
else
format.html { render :edit }
format.json { render json: #submission.errors, status: :unprocessable_entity }
end
end
end
# DELETE /submissions/1
# DELETE /submissions/1.json
def destroy
#submission.destroy
respond_to do |format|
format.html { redirect_to submissions_url, notice: 'Submission was successfully destroyed.' }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_submission
#submission = Submission.find(params[:id])
end
def set_form
#form = Form.find(params[:form_id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def submission_params
params.require(:submission).permit(:conflict, :computer, :extra_time, :am_pm)
end
end
Form Controller:
class FormsController < ApplicationController
before_action :set_form, only: [:show, :edit, :update, :destroy]
before_action :authenticate_user!, except: [:index, :show]
def index
#forms = Form.all
end
def show
#submissions = Submission.where(form_id: #form.id).order("conflict DESC")
#student = Student.find params[:id]
end
def new
#form = current_user.forms.build
end
def edit
end
def create
#form = current_user.forms.build(form_params)
respond_to do |format|
if #form.save
format.html { redirect_to #form, notice: 'Form was successfully created.' }
format.json { render :show, status: :created, location: #form }
else
format.html { render :new }
format.json { render json: #form.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /forms/1
# PATCH/PUT /forms/1.json
def update
respond_to do |format|
if #form.update(form_params)
format.html { redirect_to #form, notice: 'Form was successfully updated.' }
format.json { render :show, status: :ok, location: #form }
else
format.html { render :edit }
format.json { render json: #form.errors, status: :unprocessable_entity }
end
end
end
# DELETE /forms/1
# DELETE /forms/1.json
def destroy
#form.destroy
respond_to do |format|
format.html { redirect_to forms_url, notice: 'Form was successfully destroyed.' }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_form
#form = Form.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def form_params
params.require(:form).permit(:title, :image)
end
end
Student Controller:
class StudentsController < ApplicationController
before_action :set_student, only: [:show, :edit, :update, :destroy]
# GET /students
# GET /students.json
def index
#students = Student.all
end
# GET /students/1
# GET /students/1.json
def show
end
# GET /students/new
def new
#student = Student.new
end
# GET /students/1/edit
def edit
end
# POST /students
# POST /students.json
def create
#student = Student.new(student_params)
respond_to do |format|
if #student.save
format.html { redirect_to #student, notice: 'Student was successfully created.' }
format.json { render :show, status: :created, location: #student }
else
format.html { render :new }
format.json { render json: #student.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /students/1
# PATCH/PUT /students/1.json
def update
respond_to do |format|
if #student.update(student_params)
format.html { redirect_to #student, notice: 'Student was successfully updated.' }
format.json { render :show, status: :ok, location: #student }
else
format.html { render :edit }
format.json { render json: #student.errors, status: :unprocessable_entity }
end
end
end
# DELETE /students/1
# DELETE /students/1.json
def destroy
#student.destroy
respond_to do |format|
format.html { redirect_to students_url, notice: 'Student was successfully destroyed.' }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_student
#student = Student.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def student_params
params.require(:student).permit(:name)
end
end
If you need something else just comment and I'll provide it
Thanks for your help.
Short answer is:
...
<% #submissions.each do |submission| %>
<tr>
<td><%= submission.conflict %></td>
<td><%= submission.computer %></td>
<td><%= submission.extra_time %>%</td>
<td><%= submission.am_pm %></td>
<td><%= submission.students.first.name %></td>
</tr>
<% end %>
...
Or to not get error if submission do not have a student
<td><%= submission.students.first.try(:name) %></td>
Long answer is to change the assosiation and only add a column to submissions to link a student (student_id) and delete the jointable (submissionstudent) because you always have one student per submission.
EDIT:
to show all student's name you can do some like this
<td><%= submission.students.pluck(:name).join(' - ') %></td>
or if you need more you can iterate over students
<% #submissions.each do |submission| %>
<tr>
<td><%= submission.conflict %></td>
<td><%= submission.computer %></td>
<td><%= submission.extra_time %>%</td>
<td><%= submission.am_pm %></td>
<td>
<% submission.students.each do |ss| %>
<%= ss.name %> - <%= ss.last_name %>
<% end %>
</td>
</tr>
<% end %>