Я относительно новичок в Rails.Я пытаюсь создать приложение, которое позволяет пользователям создавать элементы видеоигр и хранить их под своими пользователями.Я использую последнюю версию Rails и Devise.
Используя скаффолдинг в качестве основы, я создал модель / контроллер видеоигры в своем приложении.После привязки моделей видеоигр к пользователю, который их создал, кажется, что любые атрибуты, введенные в форму создания, не сохраняются или, по крайней мере, просто не отображаются на странице видеоигр / указателя.После попытки поиска по Google и StackOverflow я не смог найти похожие вопросы / руководства для работы.
Есть идеи, как это исправить?Любая помощь для новичка Rails будет принята с благодарностью.
Ниже я разместил все файлы, которые могут иметь отношение к делу.Пожалуйста, дайте мне знать, если что-то еще нужно.Чтобы увидеть весь проект, см. http://github.com/bmmart2/collection-manager
Изображение после создания элемента
Указатель двух созданных элементов
Вот мой контроллер:
class VideogamesController < ApplicationController
before_action :set_videogame, only: [:show, :edit, :update, :destroy]
# GET /videogames
# GET /videogames.json
def index
if user_signed_in?
@videogame = current_user.videogames.all
else
redirect_to :root
end
end
# GET /videogames/1
# GET /videogames/1.json
def show
end
# GET /videogames/new
def new
@videogame = current_user.videogames.new
end
# GET /videogames/1/edit
def edit
end
# POST /videogames
# POST /videogames.json
def create
@videogame = current_user.videogames.create(videogame_params)
respond_to do |format|
if @videogame.save
format.html { redirect_to @videogame, notice: 'Videogame was successfully created.' }
format.json { render :show, status: :created, location: @videogame }
else
format.html { render :new }
format.json { render json: @videogame.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /videogames/1
# PATCH/PUT /videogames/1.json
def update
respond_to do |format|
if @videogame.update(videogame_params)
format.html { redirect_to @videogame, notice: 'Videogame was successfully updated.' }
format.json { render :show, status: :ok, location: @videogame }
else
format.html { render :edit }
format.json { render json: @videogame.errors, status: :unprocessable_entity }
end
end
end
# DELETE /videogames/1
# DELETE /videogames/1.json
def destroy
@videogame.destroy
respond_to do |format|
format.html { redirect_to videogames_url, notice: 'Videogame was successfully destroyed.' }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_videogame
@videogame = Videogame.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def videogame_params
params.require(:videogame).permit(:title, :publisher, :platform, :year, :condition, :upc)
end
end
Модель видеоигры:
class Videogame < ApplicationRecord
belongs_to :user
attr_accessor :title, :platform, :upc, :condition, :publisher, :year
end
Файл переноса видеоигр:1029 * Редактировать: показать вид для видеоигры
<p id="notice"><%= notice %></p>
<p>
<strong>Title:</strong>
<%= @videogame.title %>
</p>
<p>
<strong>Publisher:</strong>
<%= @videogame.publisher %>
</p>
<p>
<strong>Platform:</strong>
<%= @videogame.platform %>
</p>
<p>
<strong>Year:</strong>
<%= @videogame.year %>
</p>
<p>
<strong>Condition:</strong>
<%= @videogame.condition %>
</p>
<p>
<strong>Upc:</strong>
<%= @videogame.upc %>
</p>
<%= link_to 'Edit', edit_videogame_path(@videogame) %> |
<%= link_to 'Back', videogames_path %>