2

Update#1令人惊讶的是,如果在 Firebug 中,我将生成的 <input> HTML 更改为 <a>,它会按预期工作。但要使这个变通办法永久有效,我将不得不更改 ActiveScaffold 的代码。

Update#2现在我已经更改了 ActiveScaffold 的代码。这解决了我的问题。但问题仍未得到解答。

我有一个模型ListingMovie:

class ListingMovie
  has_many :movie_shows, :dependent => :destroy
  belongs_to :movie
  ...
  ...
end

和电影秀:

class MovieShow
  belongs_to :listing_movie

  validates_presence_of :start_time, :end_time
end

我有 Manage::ListingMoviesController:

class Manage::ListingMoviesController < Manage::BaseController
  helper Mange::MovieShowsHelper

  active_scaffold :listing_movie do |config|

    config.columns = [:movie, :listing, :start_date, :end_date, :movie_shows]
    config.columns[:listing].form_ui = :select
    config.columns[:movie].form_ui = :select
  end

  protected

  def self.active_scaffold_controller_for(klass)
    return Manage::MoviesController if klass == Movie
    return Mange::MovieShowsController if klass == MovieShow
  end
end

和管理::MovieShowsController

class Manage::MovieShowsController < Manage::BaseController
  active_scaffold :movie_show do |config|
    config.subform.columns = [:start_time, :end_time]
  end
end

当我尝试创建/更新ListingMovie 时,我看到了一个以“创建另一个电影节目”结尾的表单。早些时候,当我单击它时,它发出了一个 Ajax 请求,并在表单底部添加了两个新字段,让我可以为关联的 MovieShow 指定 start_time 和 end_time。现在,当我单击它时,不会向服务器发出任何请求。因此新字段不会添加到表单中。

以下是按钮的 HTML:

<input data-remote="true" href="/manage/listing_movies/edit_associated?association=movie_shows" id="as_manage__listing_movies--movie_shows-subform-create-another" style="" type="button" value="Create Another Movie show">

我无法调试它,因为我可以看到任何错误。单击按钮根本没有任何作用。

需要注意的一点是,如果我在表单中放入了一些错误数据,然后尝试“创建/更新”ListingMovie,则表单会再次呈现,并使用“新”表单字段来指定 start_time 和 end_time。

我正在使用 Rails 3.0.1 和 ActiveScaffold 3.0.6 谢谢!

4

1 回答 1

2

您不能在输入标签中使用 href。为按钮定义 onclick 事件或在 ancor 标签内使用它

<a href="/manage/listing_movies/edit_associated?association=movie_shows">
<input data-remote="true" id="as_manage__listing_movies--movie_shows-subform-create-another" style="" type="button" value="Create Another Movie show">
</a>

这可能对你有帮助

http://htmlhelp.com/reference/html40/forms/button.html

于 2011-08-10T08:10:19.477 回答