路由錯誤我做了一個網站,並遵循的指導,讓使用Rails的消息。但是,當我點擊 '保存',它自帶了一個路由錯誤:一個消息/條
我application_controller.rb:
class ApplicationController < ActionController::Base
def index
@articles = Article.all
end
def show
@article = Article.find(params[:id])
end
def new
end
def create
@article = Article.new(article_params)
@article.save
redirect_to @article
end
private
def article_params
params.require(:article).permit(:title, :receiver, :text)
end
protect_from_forgery with: :exception
end
我show.html.erb:
<p>
<strong>Title:</strong>
<%= @article.title %>
</p>
<p>
<strong>Receiver:</strong>
<%= @article.receiver %>
</p>
<p>
<strong>Text:</strong>
<%= @article.text %>
</p>
我的20150609013912_create_articles.rb:
class CreateArticles < ActiveRecord::Migration
def change
create_table :articles do |t|
t.string :title
t.string :receiver
t.text :text
t.timestamps
end
end
end
我的new.html.erb
<h1>New Message</h1>
<%= form_for :article do |f| %>
<p>
<%= f.label :title %><br>
<%= f.text_field :title %>
</p>
<p>
<%= f.label :receiver %><br>
<%= f.text_field :receiver %>
</p>
<p>
<%= f.label :text %><br>
<%= f.text_area :text %>
</p>
<p>
<%= f.submit %>
</p>
<% end %>
而且我index.html.erb:
<h1>Listing messages</h1>
<table>
<tr>
<th>Title</th>
<th>Receiver</th>
<th>Text</th>
</tr>
<% @articles.each do |article| %>
<tr>
<td><%= article.title %></td>
<td><%= article.receiver %></td>
<td><%= article.text %></td>
</tr>
<% end %>
</table>
此路由錯誤的結果?由於
顯示從開發完整的錯誤消息。日誌文件.. –
顯示的'articles_controller'代碼 – Prashant4224
我相信[這個答案](http://stackoverflow.com/a/23865236/1270789)介紹如何正確地實現你的'new'和'create'。 –