Rails 3 CRUD浅嵌套模型

时间:2010-06-29 14:45:06

标签: ruby-on-rails nested ruby-on-rails-3 nested-forms

我正在尝试使用this example,但它不起作用。 我猜是因为我使用的是浅嵌套模型! 我收到此错误:模板丢失

Missing template pprojects/create with {:formats=>[:html], :handlers=>[:builder, :erb, :haml, :rjs, :rhtml, :rxml], :locale=>[:en, :en]}

It looks like my app is trying to do HTML and no JS because my server console says the following:

Processing by ProjectController#create as HTML

也许我在这里遇到问题:

<%= form_for([@organization, @project], :remote => true) do |f| %>

或者因为在我的控制器中我的加载方法与创建和更新不兼容:

def load
    @projects = Project.all
    @project = Project.new
  end

def create
    @project = @organization.projects.new(params[:project])
    if @project.save
      flash[:notice] = "Successfully created project."
      @projects = Project.all
    end
  end

  def update
    @project = Project.find(params[:id])
    if @project.update_attributes(params[:project])
      flash[:notice] = "Successfully updated project."
      @projects = Project.all
    end

你有线索吗? 提前致谢

1 个答案:

答案 0 :(得分:0)

我愿意打赌你的javascript_include_tags错误的回合

尝试将它们像这样:

// include jquery before you include rails.js file - it's very important!!
javascript_include_tag 'path/to/jquery'
javascript_include_tag 'path/to/rails'

它对我有用。