Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/elixir/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Rails使用jquery Mobile将_链接到_添加_字段,而不呈现布局_Jquery_Ruby On Rails_Ruby_Jquery Mobile - Fatal编程技术网

Rails使用jquery Mobile将_链接到_添加_字段,而不呈现布局

Rails使用jquery Mobile将_链接到_添加_字段,而不呈现布局,jquery,ruby-on-rails,ruby,jquery-mobile,Jquery,Ruby On Rails,Ruby,Jquery Mobile,我使用JQuery Mobile进行标记,我注意到application_helper.rb中的link_to_add_字段不会将渲染转换为JQuery Mobile样式。这是有道理的,jquerymobile会在将其框架呈现给浏览器之前用它的框架标记这些东西。然而,有没有办法绕过这个问题并在服务器端渲染它 代码:- _certification.html.erb <fieldset> <%= f.input :certification,:input_html=&g

我使用JQuery Mobile进行标记,我注意到application_helper.rb中的link_to_add_字段不会将渲染转换为JQuery Mobile样式。这是有道理的,jquerymobile会在将其框架呈现给浏览器之前用它的框架标记这些东西。然而,有没有办法绕过这个问题并在服务器端渲染它

代码:-

_certification.html.erb
<fieldset>   
  <%= f.input :certification,:input_html=>{:class=>"string optional ui-input-text ui-body-d"} %>
     <%= link_to('#', class: "label label-inverse") do%>Remove<i class="remove-icon"></i><% end %>       
</fieldset>

_form.html.erb
 <%= f.simple_fields_for :certifications do |ed|%>
          <%= render "certifications", f: ed %>
      <% end %>  
 <%= link_to_add_fields "Add Achievement", f, :certifications,'user' %>

application_helper.rb

 def link_to_add_fields(name, f, association,controller= "")
    new_object = f.object.send(association).klass.new
    id = new_object.object_id
    fields = f.simple_fields_for(association, new_object, child_index: id) do |builder|
      render(controller.to_s + '/' + association.to_s, f: builder)
    end
    link_to(name, '#', class: "btn btn-inverse", data: {id: id, fields: fields.gsub("\n", "")})
  end

链接到添加字段是从哪里来的?它不是标准的rails或jquery,IIRC。这听起来像是railscast的产物,它的设计不一定考虑jquery_mobile

编辑 您必须将更改通知jquery mobile,以便它可以重新绘制页面。请参见增强新标记一节中的

增强新标记

页面插件发送一个pageInit事件,大多数小部件使用该事件自动初始化自己。只要小部件插件脚本被引用,它就会自动增强它在页面上找到的小部件的任何实例

但是,如果在客户端生成新标记或通过Ajax加载内容并将其注入页面,则可以触发create事件来处理新标记中包含的所有插件的自动初始化。这可以在任何元素上触发,即使是页面div本身,也可以为您节省手动初始化每个插件listview按钮、select等的任务

例如,如果一块HTML标记表示登录表单是通过Ajax加载的,则触发create事件以自动将其包含的所有小部件(在本例中为输入和按钮)转换为增强版本。此场景的代码为:

$( ...new markup that contains widgets... ).appendTo( ".ui-page" ).trigger( "create" );

link_to_add_字段是我从Railscast推荐的一种辅助方法。但是我们如何改变helper方法使其支持jquerymobile呢