我有一个Rails 3.2.12应用程序,现在我要逐步更新到4.2 ...现在我已经完成了4.0.0的第一步...
现在我遇到了一些路由问题。我的页面就像REST api一样实现了
wwww.test.de/users/7
可以很好地显示所有显示的页面...但是当我想通过Post it dosn来保存新数据时,工作得到了nil错误。 ......
我试过这个来修复routes.rb中的问题
get '/:controller(/:action(/:id))'
post '/:controller(/:action(/:id))'
但那个dosn工作......有没有办法解决这个问题?
更新
路线:
XYZ::Application.routes.draw do
resources :api_users, :as => :users
resources :api_courses, :as => :courses
resources :api_uploads, :as => :uploads
get "/super_admin(/:action(/:id))", :to => "super_admin", :constraints => {:subdomain => "admin"}
get "/", :to => redirect("/super_admin"), :constraints => {:subdomain => "admin"}
get "/super_admin(/:action(/:id))", :to => "super_admin", :constraints => {:subdomain => "admin.staging"}
get "/", :to => redirect("/super_admin"), :constraints => {:subdomain => "admin.staging"}
get "/super_admin(/:action(/:id))", :to => redirect("/")
get '/' => 'pages#home'
get '/:controller(/:action(/:id))'
post '/:controller(/:action(/:id))'
end
调用控制器功能:
def new
@course = CourseObject.find params[:id]
return false unless check_authorization @course
add_breadcrumb_for_course_object @course
add_breadcrumb "breadcrumb.new_lesson", :action => :new
@lesson = Lesson.new params[:lesson]
puts request.request_parameters
if request.post?
@lesson.sort = Lesson.count
if @lesson.save
@course.lessons << @lesson
flash[:notice] = I18n.t "flash.saved"
redirect_to :action => :edit, :id => @lesson.id
end
end
end
打印参数就像我在表单中输入的那样......
.... "lesson"=>{"name"=>"sfsdf"}}