直截了当,这里有点混乱这是我的代码
路线.rb
Rails.application.routes.draw do
namespace :main, path: ':master_url' do
root 'sites#index'
namespace :dashboard do
root 'dashboards#index'
resources :masters
end
get "/:action" => 'sites#:action'
end
root 'main/sites#index'
end
耙路线
Prefix Verb URI Pattern Controller#Action
main_root GET /:master_url(.:format) main/sites#index
main_dashboard_root GET /:master_url/dashboard(.:format) main/dashboard/dashboards#index
main_dashboard_masters GET /:master_url/dashboard/masters(.:format) main/dashboard/masters#index
POST /:master_url/dashboard/masters(.:format) main/dashboard/masters#create
new_main_dashboard_master GET /:master_url/dashboard/masters/new(.:format) main/dashboard/masters#new
edit_main_dashboard_master GET /:master_url/dashboard/masters/:id/edit(.:format) main/dashboard/masters#edit
main_dashboard_master GET /:master_url/dashboard/masters/:id(.:format) main/dashboard/masters#show
PATCH /:master_url/dashboard/masters/:id(.:format) main/dashboard/masters#update
PUT /:master_url/dashboard/masters/:id(.:format) main/dashboard/masters#update
DELETE /:master_url/dashboard/masters/:id(.:format) main/dashboard/masters#destroy
main GET /:master_url/:action(.:format) main/sites#:action
root GET / main/sites#index
主/仪表板/masters_controller.rb
class Main::Dashboard::MastersController < ApplicationController
before_action :all_masters, only: [:index, :create, :update, :destroy]
before_action :set_master, only: [:edit, :update, :destroy, :show]
before_action :init_master
layout 'main'
respond_to :html, :js
def new
@master = Master.new
end
def create
@master = Master.create(conf_params)
end
def edit
end
def update
@master.update_attributes(conf_params)
end
def destroy
@master.destroy
end
private
def all_masters
@masters = Master.all
end
def set_master
@master = Master.find(params[:id])
end
def conf_params
params.require(:master).permit(:title,:url)
end
def init_master
@master_url = Master.find_by_url(params[:master_url])
end
end
这就是我在部分渲染_form_master.html.erb时所做的,我调用了new.js.erb和edit.js.erb
$('#form-master').html("<%= j (render 'form_master', :master => @master) %>");
_form_master.html.erb内容
<%= simple_form_for [:main, :dashboard, @master], remote: true do |f| %>
<%= f.input :url, label: 'URL' %>
<%= f.input :title, label: 'Title' %>
<%= f.button :submit %>
<% end %>
问题:
当我打电话给新主人时,用这个
<%= link_to new_main_dashboard_master_path, remote: true do %>
页面呈现完美,创建大师做得很好但是当我调用编辑时,用这条线
<%= link_to :controller=>"masters",:action =>"edit",:id => master do %>
这是我之前的问题,rails 返回错误消息:
ActionView::Template::Error (No route matches {:action=>"show", :controller=>"main/dashboard/masters", :format=>nil, :id=>nil, :master_url=>#<Master id: 4, url: "test", title: "Test Aja", created_at: "2015-02-02 08:55:07", updated_at: "2015-02-02 08:55:07">} missing required keys: [:id]):
我明确地将 master.id 和 master.title 的值呈现到页面,这将返回正确的值。
问:我该如何解决这个问题?我尝试了几次,从更改 js.erb 上的本地人传递,将 @model 更改为只是模型,仍然无法正常工作
任何帮助表示赞赏,谢谢!:)