writings 中的路由
scope '/~:space_id', :module => 'dashboard', :as => 'dashboard' do
root :to => 'articles#index'
resource :billing, :only => [:show]
resources :orders, :only => [:index, :new, :create, :show, :destroy] do
collection do
post :alipay_notify
end
end
我把控制器简单写成
class SpacesController < ApplicationController
def new
@space = Space.new
end
def create
@space = Space.new(params[:space])
if @space.save
redirect_to dashboard_root_path(@space)
else
render :action => "new"
end
end
end
错误
wrong constant name ~527c3dfd1d41c84144000003Controller
rails3 的环境 如何做到像 writings 的路由分配效果?@rei
class Space
include Mongoid::Document
include Mongoid::Timestamps
field :name
field :domain
field :full_name
field :description
field :storage_used, :default => 0
has_many :mobile_articles, :dependent => :delete
# has_many :mobile_attachments, :dependent => :destroy
belongs_to :shop
index({ :shop_id => 1 })
index({ :name => 1 }, { :unique => true })
index({ :domain => 1 }, { :unique => true, :sparse => true})
def to_param
name.to_s
end
end
view space/new.html.erb
<div>空间设置</div>
<%= form_for @space, :url => '/mobile_spaces/create', :validate => true, :html => { :data => { :remote => true } } do |f| %>
<%= f.label "URL" %>
<%= f.text_field :name, :tabindex => 1, :class => "field", :placeholder => 'space-name'
%>.localhost
<br>
<%= f.label "全名" %>
<%= f.text_field :full_name, :class => "field", :tabindex => 2 %>
<br>
<%= f.label "描述" %>
<%= f.text_area :description, :class => "field", :tabindex => 3 %>
<br>
<%= f.submit "提交", :tabindex => 4%>
<% end %>
route 和 controller 就是和最上面的一样。。
抱歉,我还是看不懂问题是什么。可能你觉得我写过 writings 对这个问题了如指掌,实际是这个项目我有 1 个月没碰了,跟陌生人的代码没什么两样。所以你用“这个”,“上面一样”这种模棱两空的词语我是无法猜测你想要做什么的。
请整理你的问题:
我相信这篇文章对你有用:提问的智慧 http://www.wapm.cn/smart-questions/smart-questions-zh.html
功能:用户注册完后,进入输入域名的流程,输入域名 demo 后点提交,然后就会有 localhost/~demo/ 这个时候就出错 wrong constant name ~demoController
预期:
错误:
如果是顶楼代码,改成
redirect_to dashboard_root_path(:space_id => @space)
看看。我好像看明白在做什么了,是把 js.erb 的内容移到 controller。