Showing current category - rails - ruby-on-rails

I need to show current category name on posts index.
Insted of "Jubotron" it should shows test (when test category is chosen)
My code
Controllers
def index
#categories = Category.all
cate = params[:cate]
if !cate.nil?
#blogs = Category.find(params[:cate]).blogs
else
#blogs = Blog.all
end
end
def show
#blog = Blog.find(params[:id])
end
def new
#blog = Blog.new
end
def create
#blog = Blog.create(blog_params)
if #blog.save
redirect_to #blog
else
render :new
end
end
def edit
#finds the blog id
#blog = Blog.find(params[:id])
end
def update
#blog = Blog.find(params[:id])
if #blog.update(blog_params)
redirect_to #blog
else
render :edit
end
end
def destroy
#blog = Blog.find(params[:id])
#blog.destroy
redirect_to :action => :index
end
private
def blog_params
params.require(:blog).permit(:title, :content, category_ids: [])
end
end
before_action :set_category, only: [:show, :edit, :update, :destroy]
# GET /categories
# GET /categories.json
def index
#categories = Category.all
end
# GET /categories/1
# GET /categories/1.json
def show
end
# GET /categories/new
def new
#category = Category.new
end
# GET /categories/1/edit
def edit
end
# POST /categories
# POST /categories.json
def create
#category = Category.new(category_params)
respond_to do |format|
if #category.save
format.html { redirect_to #category, notice: 'Category was successfully created.' }
format.json { render :show, status: :created, location: #category }
else
format.html { render :new }
format.json { render json: #category.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /categories/1
# PATCH/PUT /categories/1.json
def update
respond_to do |format|
if #category.update(category_params)
format.html { redirect_to #category, notice: 'Category was successfully updated.' }
format.json { render :show, status: :ok, location: #category }
else
format.html { render :edit }
format.json { render json: #category.errors, status: :unprocessable_entity }
end
end
end
# DELETE /categories/1
# DELETE /categories/1.json
def destroy
#category.destroy
respond_to do |format|
format.html { redirect_to categories_url, notice: 'Category was successfully destroyed.' }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_category
#category = Category.find(params[:id])
end
# Only allow a list of trusted parameters through.
def category_params
params.require(:category).permit(:category)
end
end
blogs/index.html.erb
<div class="row">
<div class="col-md-8">
<h1 style="text-align:center">Jumbotron</h1>
<%= #categories.each do |category| %>
<%= category.category %>
<% end %>
<div class="row">
<% #blogs.each do |blog| %>
<div class="col-md-6">
<div class="card mt-3">
<div class="card-body">
<h3><%= link_to blog.title, blog_path(blog.id) %></h3>
<p><%= blog.content %></p>
<%= link_to "Pokaż", blog_path(blog.id), class: 'btn btn-primary' %>
<br></br>
<div class="">
Kategoria:
<% blog.categories.each do |category| %>
<a><%= link_to category.category,blogs_path(:cate => category.id) %></a>
<% end %>
</div>
</div>
</div>
</div>
<% end %>
</div>
</div>
<div class="col-md-4">
<div class="card mt-3">
<div class="card-header">
Kategorie:
</div>
<div class="card-body">
<ul class="list-group">
<% #categories.each do |category| %>
<li class="list-group-item d-flex justify-content-between align-items-center">
<%= link_to category.category, blogs_path(:cate => category.id) %>
<span class="badge badge-primary badge-pill"><%= category.blogs.count %></span>
</li>
<% end %>
</ul>
</div>
</div>
</div>
</div>
</div>
and for example I can show category name in categories/show.htm.erb
but when I past it into Blogs index it gives me an error that category method is undefined.
<strong>Category:</strong>
<%= #category.category %>
</p> ```
Any ideas?

Your issue is where you are placing your 'Jumbotron' code. Currently, you're hardcoding the word 'Jumbotron' like this:
<h1 style="text-align:center">Jumbotron</h1>
You should move this inside the code where you are iterating over the categories:
<% #categories.each do |category| %>
<h1 style="text-align:center"><%= category.category %></h1>
<% end %>
Keep in mind, if you have more than one category, this is going to give you multiple <h1> tags; one for each category.

On the index page you are looping through the categories <% #categories.each do |category| %> thus you should use category.category and not #category.category inside the block

Related

Undefined method `errors' for nil:NilClass - when I click on Form Submit

I have added validation to the form FORM. So whenever I click on the create employee with all the details it works but when I do not put the values I get this error. I have even changed to #employee in form_with.
I just want validations to be seen. How do I handle this?
Employees Controller:
class EmployeesController < ApplicationController
before_action :set_employee, only: %i[ show edit update destroy]
# GET /employees or /employees.json
def index
#employees = Employee.all
end
# GET /employees/1 or /employees/1.json
def show
end
# GET /employees/new
def new
#employee = Employee.new
end
# GET /employees/1/edit
def edit
end
# POST /employees or /employees.json
def create
employee_service = EmployeeCreationService.new(employee_params)
respond_to do |format|
if employee_service.execute!
format.html { redirect_to employee_service.employee}
# format.json { render :show, status: :created, location: #employee }
else
format.html { render :new, status: :unprocessable_entity }
# format.json { render json: #employee.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /employees/1 or /employees/1.json
def update
respond_to do |format|
if #employee.update(employee_params)
format.html { redirect_to #employee}
# format.json { render :show, status: :ok, location: #employee }
else
format.html { render :edit, status: :unprocessable_entity }
# format.json { render json: #employee.errors, status: :unprocessable_entity }
end
end
end
# DELETE /employees/1 or /employees/1.json
def destroy
#employee.destroy
respond_to do |format|
format.html { redirect_to employees_url}
# format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_employee
#employee = Employee.find(params[:id])
end
# Only allow a list of trusted parameters through.
def employee_params
params.require(:employee).permit(:name, :phone, :designation_id, :email, :password)
end
end
Form:
<%= form_with(model: employee, local: true) do |form| %>
<% if employee.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(employee.errors.count, "error") %> prohibited this employee from being saved:</h2>
<ul>
<% employee.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="form-group row">
<%= form.label :name,class:"col-sm-2 col-form-label" %>
<div class="col-sm-10">
<%= form.text_field :name %>
</div>
</div>
<div class="form-group row">
<%= form.label :phone,class:"col-sm-2 col-form-label" %>
<div class="col-sm-10">
<%= form.text_field :phone %>
</div>
</div>
<div class="form-group row">
<%= form.label :designation_id,class:"col-sm-2 col-form-label" %>
<div class="col-sm-10">
<%= form.select :designation_id, [["SOFTWARE ENGINEER", "2"], ["SERVICE ENGINEER", "3"]] %>
</div>
</div>
<div class="form-group row">
<%= form.label :Email,class:"col-sm-2 col-form-label" %>
<div class="col-sm-10">
<%= email_field_tag 'employee[email]' %>
</div>
</div>
<div class="form-group row">
<%= form.label :Password,class:"col-sm-2 col-form-label" %>
<div class="col-sm-10">
<%= password_field_tag 'employee[password]' %>
</div>
</div>
<br />
<div class='form-group'>
<div class="align-left">
<h5 align="left">
<%= form.submit class:"btn btn-dark"%>
</h5></button>
</div>
<div class="align">
<div >
<%= link_to 'Go Back', employees_path , class:"btn btn-primary btn-sm"%>
</div>
</div>
</div>
<% end %>
Service - to create employee and User simultaneously(Using Devise):
class EmployeeCreationService
attr_reader :employee
def initialize(employee_params)
#employee_params = employee_params.except(:email, :password)
#user_params = employee_params.slice(:email, :password)
end
def execute!
begin
#employee = Employee.create!(#employee_params)
User.create!(#user_params.merge(employee: employee))
rescue => exception
#ex = exception
return false
end
true
end
end
I suppose the problem in the create action in else branch of condition:
The form needs that #employee variable should be set but it isn't for this case.
You need to have the ability to have an instance of the Employee class from your service. Something like this:
#employee = employee_service.execute!
if #employee.valid?
redirect_to
else
render
def create
#employee = Employee.new(employee_valid)
employee_service = EmployeeCreationService.new(employee_params)
respond_to do |format|
if employee_service.execute!
format.html { redirect_to employee_service.employee}
else
format.html { render :new, status: :unprocessable_entity }
end
end
end
Made these changes and it works fine now. For the validations, I have added JS.
Also slice employeee params with only the name phone and designation.

How to add comments to statuses (like facebook)

I am trying to improve an exercice that I did on treehouse, the idea was to remake a little version of facebook thing, where users could publish statuses.
Now I want that a user can comment any statuses... And I am kinda lost...
The idea is to have all on the same page (if possible?, like on the real facebook)
So the comment form and the "displaying" content...
I hope anyone could help me :)
This is my github repository
I think I haven't understand how to call variables from a controller to another...
If someone could explain me with very easy words ... I am not native english speaker... so sometime it's difficult..
Here are the statuses part
controllers/statuses_controller/rb
class StatusesController < ApplicationController
before_filter :authenticate_user!, only: [:new, :create, :edit, :update]
before_action :set_status, only: [:show, :edit, :update, :destroy]
def index
#statuses = Status.all
#comments = Comment.all
end
def show
#status = Status.find(params[:id])
#comments = #status.comments.all
end
def new
#status = Status.new
#comment = #status.comments.build
end
def create
#status = Status.new(status_params)
#status.user = current_user
respond_to do |format|
if #status.save
format.html { redirect_to #status, notice: 'Status was successfully created.' }
format.json { render :show, status: :created, location: #status }
else
format.html { render :new }
format.json { render json: #status.errors, status: :unprocessable_entity }
end
end
end
def update
respond_to do |format|
if #status.update(status_params)
format.html { redirect_to #status, notice: 'Status was successfully updated.' }
format.json { render :show, status: :ok, location: #status }
else
format.html { render :edit }
format.json { render json: #status.errors, status: :unprocessable_entity }
end
end
end
def destroy
#status.destroy
respond_to do |format|
format.html { redirect_to statuses_url, notice: 'Status was successfully destroyed.' }
format.json { head :no_content }
end
end
private
def set_status
#status = Status.find(params[:id])
end
def status_params
params.require(:status).permit(:user_id, :content, :comments_attribute[:id, :status_id, :content])
end
end
models/status.rb
class Status < ActiveRecord::Base
belongs_to :user
has_many :comments
default_scope -> { order(created_at: :DESC)}
validates :content, presence: true,
length: {minimum: 2}
validates :user_id, presence: true
end
views/comments/_form.html.erb I create a render in my index below:
<% simple_form_for #status.comments do |f|%>
<%= f.input :content %>
<%= f.button :submit %>
<% end %>
view/statuses/index.html.erb
<div class="page-header">
<h1>All of the Statuses</h1>
</div>
<%= link_to "Post A New Status", new_status_path, class: "btn btn-success"%>
<br>
<br>
<% #statuses.each do |status| %>
<div class="status">
<div class="row">
<div class="col-xs-1 avatar">
<%= image_tag status.user.avatar.thumb if status.user.avatar?%>
</div>
<div class="col-xs-7">
<h4><%= status.user.full_name%></h4>
</div>
</div>
<div class="row">
<div class="col-xs-8">
<p><%= simple_format(status.content) %></p>
</div>
</div>
<div class="row">
<div class="col-xs-8">
<%= link_to time_ago_in_words(status.created_at) + " ago", status %>
<% if status.user == current_user %>
<span class="admin">
| <%= link_to "Edit", edit_status_path(status) %> |
<%= link_to "Delete", status, method: :delete, data: {confirm: "Are you sure?"} %>
</span>
<% end %>
</div>
</div>
<div class="row">
<div class="col-xs-12">
<p>Comments</p>
<% #comments.each do |comment| %>
<%= comment.content %>
<% end %>
</div>
</div>
<div class="row">
<div class="col-xs-12">
<%= render "comments/form" %>
</div>
</div>
</div>
Now the comments part:
model/comment.rb
class Comment < ActiveRecord::Base
belongs_to :status
belongs_to :user
end
controllers/comments_controller.rb
class CommentsController < ApplicationController
def create
#comment = Comment.new(params_comment)
end
def index
#statuses = Status.all
#comments = Comment.all
#comment = Comment.find_by(params[:id])
end
private
def params_comment
params.require(:comment).permit(:content)
end
end
routes.rb
resources :statuses do
resources :comments
end
user.rb
that's a part of what I have in there
has_many :statuses
has_many :comments
your comments creation method should look like this:
#status = Status.find(params[:status_id])
#comment = #status.comments.create(comment_params)
#comment.user_id = current_user.id if current_user
#comment.save

Search function not working in rails

I am trying to implement a search form in my rails app (https://dedesign.herokuapp.com/) and it's not returning anything (not even the search query is coming up in the terminal or url). Here is my application.html.erb:
<!DOCTYPE html>
<html>
<head>
<title>Danielle's Calligraphy Services</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1">
<%= csrf_meta_tags %>
</head>
<body>
<% if notice %>
<p class="alert alert-info" role="alert"><%= notice %></p>
<% end %>
<% if alert %>
<p class="alert alert-warning" role="alert"><%= alert %></p>
<% end %>
<nav>
<div class="navbar navbar-default navbar-fixed-top" id="myNavbar">
<div class="container-fluid">
<form class="navbar-form navbar-left" role="search">
<div class="form-group">
<%= form_tag("/products", method: "get", class: "form-inline") do %>
<%= text_field_tag(:q, " ", class: "form-control") %>
<%= submit_tag("Search", class: "btn btn-default") %>
<% end %>
</div>
</form>
<ul class="nav navbar-nav navbar-right">
<li><%= link_to "Home", static_pages_index_path %></li>
<li><%= link_to "About", static_pages_about_path %></li>
<li><%= link_to "Contact", static_pages_contact_path %></li>
<li><%= link_to "Products", products_path %></li>
<li>
<% if user_signed_in? %>
<%= link_to('Logout', destroy_user_session_path, :method => :delete) %>
<% else %>
<%= link_to('Login', new_user_session_path) %>
<% end %>
</li>
</ul>
</div> <!-- end navbar collapse -->
</div>
</nav>
<%= yield %>
<footer>
<div class="copyright">
© 2016 Danielle Bukvic
</div>
</footer>
</body>
</html>
And my products_controller.rb
class ProductsController < ApplicationController
before_action :set_product, only: [:show, :edit, :update, :destroy]
respond_to :json, :html
# GET /products
# GET /products.json
def index
if params[:q]
search_term = params[:q]
#products = Product.where("name LIKE ?", "%#{search_term}%")
else
#products = Product.all
end
respond_with #products
end
# GET /products/1
# GET /products/1.json
def show
#comments = #product.comments.order("created_at DESC").paginate(page: params[:page], :per_page => 1)
end
# GET /products/new
def new
#product = Product.new
end
# GET /products/1/edit
def edit
end
# POST /products
# POST /products.json
def create
#product = Product.new(product_params)
respond_to do |format|
if #product.save
format.html { redirect_to #product, notice: 'Product was successfully created.' }
format.json { render :show, status: :created, location: #product }
else
format.html { render :new }
format.json { render json: #product.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /products/1
# PATCH/PUT /products/1.json
def update
respond_to do |format|
if #product.update(product_params)
format.html { redirect_to #product, notice: 'Product was successfully updated.' }
format.json { render :show, status: :ok, location: #product }
else
format.html { render :edit }
format.json { render json: #product.errors, status: :unprocessable_entity }
end
end
end
# DELETE /products/1
# DELETE /products/1.json
def destroy
#product.destroy
respond_to do |format|
format.html { redirect_to products_url, notice: 'Product was successfully destroyed.' }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_product
#product = Product.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def product_params
params.require(:product).permit(:name, :description, :image_url, :colour, :price)
end
end
Here is my code in GitHub in case you need to access anything else:https://github.com/dbukvic/nameofapp

Ruby on Rails Goal has-many Steps association. How to create steps for a goal?

I'm trying to create a has-many association within a ruby on rails app where a user has-many goals and a goal has-many steps
I can't seem to figure out how to link the creation of a Step for a certain Goal. I've been playing around with it for a while and looking around on here but haven't found a solution.
Below are my Goal_controller, Step_Controller, Step form, and Goal form
Goal Controller:
class GoalsController < ApplicationController
before_action :set_goal, only: [:show, :edit, :update, :destroy]
before_filter :authorize
# GET /goals
# GET /goals.json
def index
#goals = Goal.all
end
# GET /goals/1
# GET /goals/1.json
def show
#goal = Goal.find(params[:id])
session[:current_goal] = #goal.id
end
# GET /goals/new
def new
#goal = Goal.new
end
# GET /goals/1/edit
def edit
end
# POST /goals
# POST /goals.json
def create
#goal = current_user.goals.new(goal_params)
respond_to do |format|
if #goal.save
format.html { redirect_to #goal, notice: 'Goal was successfully created.' }
format.json { render :show, status: :created, location: #goal }
else
format.html { render :new }
format.json { render json: #goal.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /goals/1
# PATCH/PUT /goals/1.json
def update
respond_to do |format|
if #goal.update(goal_params)
format.html { redirect_to #goal, notice: 'Goal was successfully updated.' }
format.json { render :show, status: :ok, location: #goal }
else
format.html { render :edit }
format.json { render json: #goal.errors, status: :unprocessable_entity }
end
end
end
# DELETE /goals/1
# DELETE /goals/1.json
def destroy
#goal.destroy
respond_to do |format|
format.html { redirect_to goals_url, notice: 'Goal was successfully destroyed.' }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_goal
#goal = Goal.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def goal_params
params.require(:goal).permit(:Goal, :Description, :Date, :DueDate, :user_id)
end
end
Step Controller:
class StepsController < ApplicationController
#before_action :set_step, only: [:show, :edit, :update, :destroy]
before_filter :authorize
# GET /steps
# GET /steps.json
def index
#steps = Goal.find(params[:goal_id]).steps.all
end
def new
#step = Goal.find(params[:goal_id]).steps.new
end
# GET /steps/1
# GET /steps/1.json
def show
end
# GET /steps/1/edit
def edit
end
def create
#step = Goal.find(params[:goal_id]).steps.new(step_params)
respond_to do |format|
if #step.save
format.html { redirect_to #step, notice: 'Step was successfully created.' }
format.json { render :show, status: :created, location: #step }
else
format.html { render :new }
format.json { render json: #step.errors, status: :unprocessable_entity }
end
end
redirect_to(goal_steps_url(#goal))
end
def update
#step.update(step_params)
respond_to do |format|
if #step.update(step_params)
format.html { redirect_to #step, notice: 'Step was successfully updated.' }
format.json { render :show, status: :ok, location: #step }
else
format.html { render :edit }
format.json { render json: #step.errors, status: :unprocessable_entity }
end
end
end
# POST /steps
# POST /steps.json
def destroy
#step.destroy
respond_to do |format|
format.html { redirect_to steps_url, notice: 'Step was successfully destroyed.' }
format.json { head :no_content }
end
end
private
def set_step
#step = Goal.find(params[:goal_id]).Step.find(params[:id])
end
def step_params
params.require(:step).permit(:requirement, :completionTime, :goal_id)
end
end
Step Form:
<%= form_for(#step) do |f| %>
<% if #step.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(#step.errors.count, "error") %> prohibited this step from being saved:</h2>
<ul>
<% #step.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :requirement %><br>
<%= f.text_field :requirement %>
</div>
<div class="field">
<%= f.label :completionTime %><br>
<%= f.number_field :completionTime %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
Goal Form:
<%= form_for(#goal) do |f| %>
<% if #goal.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(#goal.errors.count, "error") %> prohibited this goal from being saved:</h2>
<ul>
<% #goal.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :Goal %><br>
<%= f.text_field :Goal %>
</div>
<div class="field">
<%= f.label :Description %><br>
<%= f.text_area :Description %>
</div>
<div class="field">
<%= f.label :Date %><br>
<%= f.date_select :Date %>
</div>
<div class="field">
<%= f.label :DueDate %><br>
<%= f.date_select :DueDate %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
It looks like you will be missing your goal_id when you submit your step creation form. You will need to store it either in a hidden field in your step form, or as part of the route (e.g. POST /goals/10/steps).

Rails, edit link will redirect but update button won't work

In my rails app I have this edit form that does not seem to work properly. If I enter the edit-site through any link, everything will look fine but the form submit button will not work. If I refresh the window it works fine.
Edit.html.erb
<div class="alien-choice">
<h2 class="player_name"><%= current_user.username %></h2>
<p> Choose <span>0</span>/2 Power</p>
<%= form_for [#gameround, #currentplayer] do |f| %>
<% alleflares = #currentplayer.flares %>
<% alleflares.each { |val|
printAlien = Alien.find_by_title(val)
%>
<div class="alien_wrap">
<h3><%= printAlien.title %> <span>[<%= printAlien.expansion.abbr %>]</span></h3>
<label for="<%= printAlien.title %>">
<div class="alien" style="background-image: url(<%= printAlien.avatar.url %>)">
</label>
<%= f.check_box(:aliens, { :multiple => true, :id => printAlien.title, :class => 'choosealiens'}, printAlien.title, nil) %>
</div>
</div>
<% } %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
<%= link_to 'Back', gameround_currentplayers_path %>
The controller
class CurrentplayersController < ApplicationController
before_action :set_currentplayer, only: [:show, :edit, :update]
# GET /currentplayers
# GET /currentplayers.json
def index
#currentplayers = Currentplayer.all
end
# GET /currentplayers/1
# GET /currentplayers/1.json
def show
#gameround = Gameround.find(params[:gameround_id])
#currentplayer = #gameround.currentplayers.find(params[:id])
current_user
end
# GET /currentplayers/new
def new
#gameround = Gameround.find(params[:gameround_id])
#currentplayer = Currentplayer.new
end
# GET /currentplayers/1/edit
def edit
#gameround = Gameround.find(params[:gameround_id])
#currentplayer = #gameround.currentplayers.find(params[:id])
end
# POST /currentplayers
# POST /currentplayers.json
def create
#gameround = Gameround.find(params[:gameround_id])
#currentplayer = #gameround.currentplayers.create(currentplayer_params);
respond_to do |format|
if #currentplayer.save
format.html { redirect_to #gameround, notice: 'Currentplayer was successfully created.' }
format.json { render :show, status: :created, location: #currentplayer }
else
format.html { render :new }
format.json { render json: #currentplayer.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /currentplayers/1
# PATCH/PUT /currentplayers/1.json
def update
#gameround = Gameround.find(params[:gameround_id])
#currentplayer = #gameround.currentplayers.find(params[:id])
if #currentplayer.update(currentplayer_params)
redirect_to gameround_currentplayer_path
else
render 'edit'
end
end
# DELETE /currentplayers/1
# DELETE /currentplayers/1.json
def destroy
#gameround = Gameround.find(params[:gameround_id])
#currentplayer = #gameround.currentplayers.find(params[:id])
#currentplayer.destroy
respond_to do |format|
format.html { redirect_to '/play', notice: 'Currentplayer was successfully destroyed.' }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_currentplayer
#currentplayer = Currentplayer.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def currentplayer_params
params.require(:currentplayer).permit(:log_id, :flares, :winner, :bases, :gameround_id, aliens:[])
end
end
config.routes
Rails.application.routes.draw do
resources :gamerounds do
resources :currentplayers
end
I figured it out. It was just because the submit button was outside of the main div. Sorry for the trouble!
You want to create your routes into config/routes.rb as follows:
resources :current_players

Resources