【发布时间】:2015-05-24 07:45:46
【问题描述】:
好吧,我知道有一百万个帖子,但我似乎无法找到解决我的问题的方法。我是 Rails 新手,在 bloc 完成指导后才开始我的第一个个人项目。
我遇到了这个错误:
没有路由匹配 [POST] "/registered_applications/new"
这是我的路线:
Rails.application.routes.draw do
resources :registered_applications
devise_for :users
get 'about' => 'welcome#about'
root :to => 'welcome#index'
end
这是表格。单击提交时,我们遇到了错误:
我正在尝试
<%= form_for @application do |f| %>,但我遇到了一个错误,所以我改用了这个。这里的任何建议也将不胜感激。
<h3 class="roboto">Register a new application</h3>
<div class="row">
<div class="col-md-4">
<p>Application Registration Guidelines:</p>
<ul>
<li>Applications must be named.</li>
<li>You must provide a URL.</li>
<li>You must be signed in to add an application to your account.</li>
</ul>
</div>
<div class="col-md-8 app-reg">
<%= form_for(:application) do |f| %>
<div class="form-group">
<%= f.label :name %>
<%= f.text_field :name, class: 'form-control', placeholder: "Application name" %>
</div>
<div class="form-group">
<%= f.label :URL %>
<%= f.text_field :URL, class: 'form-control', placeholder: "Application URL" %>
</div>
<div class="form-group">
<%= f.submit "Save", class: 'btn btn-primary' %>
</div>
<% end %>
</div>
</div>
这是我的控制器:
绝对是一个正在进行中的工作
class RegisteredApplicationsController < ApplicationController
def index
@applications = Application.all
end
def new
@application = Application.new
end
def show
@application = Application.find(params[:id])
end
def edit
@application = Application.find(params[:id])
end
def create
@application = Application.new(application_params)
if @application.save
flash[:notice] = "Application was saved successfully."
redirect_to @application
else
flash[:error] = "There was an error creating the application. Please try again."
render :new
end
end
end
private
def application_params
params.require(:application).permit(:name, :URL)
end
如果你觉得有必要看看,这里是应用模型:
class Application < ActiveRecord::Base
belongs_to :user
end
非常感谢任何帮助。
【问题讨论】:
标签: ruby-on-rails controller routes