我试图浏览导轨指南(http://guides.rubyonrails.org/getting_started.html),但在尝试更新图书时遇到问题: ActionController::ParameterMissing in BooksController#update
以下是图书管理员中的更新和编辑方法:
def edit
@book = Book.find(params[:id])
end
def update
@books = Book.find(params[:id])
if @book.update(book_params)
redirect_to @book
else
render 'edit'
end
end
还有book_params定义:
private
def book_params
params.require(:books).permit(:author, :title)
end
这是我使用的编辑视图表单:
<%= form_for :book, url: book_path(@book), method: :patch do |f| %>
我不确定为什么会出现这个错误,因为使用基本相同的文章代码(如指南中所示)可以正常工作。
答案 0 :(得分:0)
表单不正确,您必须在发送之前添加book密钥。
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.me</groupId>
<artifactId>GankALane</artifactId>
<version>1.0-SNAPSHOT</version>
<repositories>
<repository>
<id>beam-releases</id>
<url>https://maven.beam.pro/content/repositories/releases/</url>
</repository>
<repository>
<id>beam-snapshots</id>
<url>https://maven.beam.pro/content/repositories/snapshots/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>pro.beam</groupId>
<artifactId>api</artifactId>
<version>1.10.5-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>pro.beam</groupId>
<artifactId>interactive</artifactId>
<version>1.5.0-SNAPSHOT</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>com.me.GankALane.Main</mainClass>
</manifest>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</archive>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>