How to put "create.html.erb" in a modal?

时间:2016-02-12 21:29:23

标签: ruby-on-rails ruby bootstrap-modal

The modal is popping up for agent.page.at("a.name-page-link")["href"] , but not new.html.erb. Why?

A user clicks "+ Challenge" on create.html.erb:

header.html.erb

header.html.erb

A modal pops up for <%= link_to new_challenge_path, data: { modal: true } do %> <span class="glyphicon glyphicon-plus"></span> <b>Challenge</b> <% end %> :

new.html.erb

new.html.erb

challenges_controller

<%= simple_form_for(@challenge, html: { data: { modal: true } })  do |f| %>
 etc...
<% end %>

And once the user clicks def new @challenge = Challenge.new respond_modal_with @challenge end def create @challenge = Challenge.new(challenge_params) if params[:step] == '2' respond_modal_with @challenge @challenge = current_user.challenges.build(challenge_params) @challenge.save end end on f.submit he is redirected_to new.html.erb since it is create.html.erb in the process. I want :step, 2 to also be in a modal though, which for some reason it is not.

create.html.erb

create.html.erb

1 个答案:

答案 0 :(得分:0)

你这样做是错误的,因为创建行动的工作就是使用通过参数传递给它的数据来创建资源。

HTTP方法

这些是HTTP方法GET,POST,PUT,DELETE。其中只有GET具有与之相关的任何类型的视图,其他类型用于创建,更新和删除资源。由于创建操作属于POST类型,因此它不能具有任何视图。更多信息here

所以来解决方案你的要求是逐步从用户那里获取数据,你可以利用这个jquery plugin在单个文件new.html.erb中做你不需要单独的文件表格中的每一步。