【问题标题】:"Create Another XXX" button not working in ActiveScaffold“创建另一个 XXX”按钮在 ActiveScaffold 中不起作用
【发布时间】:2011-08-10 06:30:15
【问题描述】:

Update#1 令人惊讶的是,如果在 Firebug 中,我将生成的 HTML 更改为 ,它会按预期工作。但要使这种解决方法永久化,我将不得不更改 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 谢谢!

【问题讨论】:

    标签: ruby-on-rails ruby-on-rails-3 activescaffold


    【解决方案1】:

    您不能在输入标签中使用 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

    【讨论】:

    • 我没有在anchor标签内放置input标签,而是只使用anchor标签。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多