Tag: partial views

如何实现这个嵌套的linked_to_function?

在我看来,我希望用户能够浏览产品目录。 层次结构如下: Category Product AdditionalInfoForm 在我的主视图中,我为类别呈现部分: #opContent = render :partial => ‘op_main_categories’ op_main_categories partial定义如下: – @controller.getPortalCategories.each do |c| = link_to_function “#{c.name}”, :class => ‘opCategoryHeaderText’ do |page| – partial = escape_javascript(render :partial => ‘op_secondary_categories’, :locals => { :c => c }) – page << "$('opContent').update(\"#{partial}\")" 当用户单击上面部分中的链接时,产品将通过op_secondary_categories部分呈现: – @controller.getPortalProductsForCategory(c).each do |p| = link_to_function “#{p.name}”, :class => ‘opCategoryHeaderText’ […]

渲染部分视图时ajax中的动态内容

当用户点击不同的链接时,如何获得动态内容? 视图/仪表板/ index.html.haml .container – @trips.each do |trip| = link_to trip.id, quick_view_trips_path, remote: true 我很确定quick_view_trips_path是不正确的,因为所有链接都是这样的: 1 13 51 不知何故,我需要使这些链接动态化,然后当用户点击它时,模态窗口也将是动态的。 如果我用quick_view_trips_path替换quick_view_trips_path = link_to trip.id, trip, remote: true 没有任何反应,并且url会更改为正确的url,但我的模态窗口不会通过ajax呈现。 以下是url现在的样子: 1 除了我想用动态内容完成的事情,有没有办法可以改变我的url: 1 是否可以获取?quick_view=on附加到URL的末尾并使一切工作再次起作用? 以下是我的其余代码: 意见/车次/ quick_view.js.erb $(‘body’).append(”); 意见/车次/ _quick_view.html.haml .root-container = @trip.title = @trip.image = @trip.more_details 这现在无法正常工作,因为我的应用程序返回undefined method 的routes.rb resources :trips do collection do get ‘quick_view’ […]

使用will_paginate gem在rails 3.2.3中调用Ajax

我试图用will_paginate gem实现一个Ajax调用,我发现这个指南http://ramblinglabs.com/blog/2011/11/rails-3-1-will_paginate-and-ajax看起来像一个简单的解决方案,尽管它包括我不熟悉的coffeescript,所以如果有人有不同的解决方案,请告知.. 我的代码如下 我的看法 我的部分(userrecipes) 90 %> “Are you sure?”, :method => :delete %> ‘favourites’, :action => ‘create’, :recipe_id => r.id}, {:method => :post } %> 更新了userrecipes.js.erb文件 $(‘#userRecipes’).html(”); $.setAjaxPagination(); CoffeeScript的 $ -> $.setAjaxPagination = -> $(‘.pagination a’).click (event) -> event.preventDefault() loading = $ ” $(‘.other_images’).prepend loading loading.fadeIn() $.ajax type: ‘GET’, url: $(@).attr(‘href’), dataType: ‘script’, success: […]

如何为Rails的部分渲染查找添加视图路径?

我想拥有以下目录结构: views/ app1/ users/_user.html.erb users/index.html.erb app2/ users/index.html.erb shared/ users/_user.html.erb users/index.html.erb 在我看来,我打电话 # app1/users/index.html “user” %> # => /app1/users/_user.html.erb # app2/users/index.html “user” %> # => /shared/users/_user.html.erb 所以基本上,如何告诉Rails检查/ app2 / users dir然后检查共享目录,然后再提出它丢失了模板错误? 更新 我解决了这个问题(正如Senthil所建议的那样,使用File.exist? 这是我的解决方案 – 欢迎提供反馈和建议 # application_helper.rb # Checks for a partial in views/[vertical] before checking in views/shared def partial_or_default(path_name, options={}, &block) path_components = path_name.split(“/”) […]

从rake任务渲染视图

我正在尝试从rake任务发送邮件。 我已经设法发送电子邮件,但问题是我发送的文件。 我想发送一个视图,每次发送邮件时都会修改。 我已经安装了gem render_anywhere来渲染我的rake任务中的视图但是我一直有这个错误: NoMethodError:字符串的未定义方法`formats’:0x007ff1a1068b88> 这是我的rake任务的一部分,应该做的工作: require’grand_anywhere’包括RenderAnywhere需要Rails.root.join(’app’,’helpers’,’reports_helper’) namespace:reports do desc’将视图写入文件的示例’任务:example =>:environment do class RakeActionView Report.first ) html = view.render(:template =>”#{Rails.root}/app/views/reports/organize.html.erb”, layout: false) pdf = PDFKit.new(html) pdf.stylesheets << "#{Rails.root}/app/assets/stylesheets/print/reports-print.css.scss"