“创建另一个XXX”按钮在 ActiveScaffold 中不起作用
Update#1 令人惊讶的是,如果在 Firebug 中,我将生成的 更改为HTML 到 ,它按预期工作。但为了使这个解决方法永久有效,我将不得不更改 ActiveScaffold 的代码。
Update#2 现在我已经更改了 ActiveScaffold 的代码。这解决了我的问题。但问题仍然没有答案。
我有一个模型 ListingMovie:
class ListingMovie
has_many :movie_shows, :dependent => :destroy
belongs_to :movie
...
...
end
和 MovieShow:
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
和 Manage::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 谢谢!
Update#1 Surprisingly if in Firebug, I change the generated <input> HTML to <a>, it works as expected. But to make this workaround permanent, I will have to change ActiveScaffold's code.
Update#2 For now I have changed the code of ActiveScaffold. This solves my problem. But the questions is still not answered.
I have a model ListingMovie:
class ListingMovie
has_many :movie_shows, :dependent => :destroy
belongs_to :movie
...
...
end
and MovieShow:
class MovieShow
belongs_to :listing_movie
validates_presence_of :start_time, :end_time
end
I have 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
and Manage::MovieShowsController
class Manage::MovieShowsController < Manage::BaseController
active_scaffold :movie_show do |config|
config.subform.columns = [:start_time, :end_time]
end
end
When I try to create/update a ListingMovie, I am shown a form that has a "Create Another Movie Show" the end. Earlier when I clicked it, it made an Ajax request and added two new fields at the bottom of the form that let me specify start_time and end_time for associated MovieShow. Now When I click on it, no request is made to the server. And hence new fields are not added to the form.
Following is the HTML of the button:
<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">
I am unable to debug this as I can see any errors. Clicking the button simply does nothing.
One thing to notice is that if I put some erroneous data in the form and then try to "Create/Update" a ListingMovie, the form is rendered again with a "new" form fields to specify start_time and end_time.
I am using Rails 3.0.1 and ActiveScaffold 3.0.6
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不能在输入标记中使用 href。
为按钮定义 onclick 事件或在 ancor 标记内使用它,
这可能对您有帮助
http ://htmlhelp.com/reference/html40/forms/button.html
You cannot use href in a input tag.
Define an onclick event for the button or use it inside an ancor tag
this may be helpful to you
http://htmlhelp.com/reference/html40/forms/button.html