Tag: 渲染

在backbone.js + rails中渲染视图

我试图在我的根页面上呈现视图“new_view.js.coffee”(创建用户的表单)。 我正在使用rails-backbone gem,到目前为止我有这个: 应用程序/视图/家/ index.html.erb Loading… $(function() { window.newView = new Example.Views.Users.NewView({model: users}); newView.render(); Backbone.history.start(); }); 它基本上是这个的副本(来自rails-backbone README.md): 应用程序/视图/职位/ index.html.erb $(function() { // Blog is the app name window.router = new Example.Routers.PostsRouter({posts: }); Backbone.history.start(); }); 我的新观点是这样的: 资产/ Java脚本/骨干网/视图/用户/ new_view.js.coffee Example.Views.Users ||= {} class Example.Views.Users.NewView extends Backbone.View template: JST[“backbone/templates/users/new”] events: “submit #new-user”: “save” constructor: (options) -> […]

在ajax中呈现的Rails 3表单获取与text_fields值混合的html

我用这种方式通过ajax渲染表单: $(‘#details’).html(“”); 感谢d11wtq! 现在的问题是这个表单是一个渲染,一些html作为文本! 虽然text-feild和text-area中的所有值都是正确的。 这是表格 true, :html => { :’data-type’ => ‘html’, :id => ‘new-note-form’ } do |f| %> prohibited this note from being saved: @note.wine.id %> “60×12” %> 因此,当渲染此表单时,在块 Comes Red Wine div>之后打印出来。 在文本字段中有值和一些html。 在文本区域也一样。 插入的html代码总是一些,所以它不是随机的。 谢谢你的时间和帮助:)

在ajax获取请求后,rails渲染部分

我在我的Rails 3应用程序中使用Jvectormap。 当我点击它时,我想隐藏地图并使用有关所选国家/地区的信息可视化部分。 我处理地图点击,然后向服务器发送GET请求。 users.js.coffee.erb $ -> $(“#world-map”).vectorMap onRegionClick: (event, code) -> $(‘#world-map’).hide(1000) $.get(‘/users/statistics’, {code: code}); $(‘#statistics’).show(1000) users_controller.rb def statistics @country = Country.find_by_two_letter_code((params[:code]).downcase) render :nothing => true 结束 这是回应 在2013-06-02 17:54:49 +0200开始获取127.0.0.1的GET“/ users / statistics?code = ET” 由UsersController处理#statistics为/ 参数:{“code”=>“ET”} 国家负荷(0.2ms)选择“国家”。* FROM“国家”地点 “countries”。“two_letter_code”=’et’LIMIT 1 渲染文本模板(0.0ms) 2ms完成200 OK(浏览次数:0.6ms | ActiveRecord:0.2ms) 和观点 show.html.erb {:country => @country} %> _statistics.html.erb […]

Rails在渲染后强制重新加载javascript

我在我的rails应用程序中使用了一个表单,在我的控制器中最后检查表单的内容是否正常,如果不是我再次渲染页面解释错误 控制器的一部分 if @insertion.save redirect_to @insertion else render ‘new’ end 在我看来,我有这条线来显示错误。 The form contains . 问题是渲染后页面不会再次加载我的javascript文件,因此视图不像我预期的那样 如何在渲染后强制重新加载js? 由于turbolink,这是我的咖啡文件 $(document).on “turbolinks:load”, -> insertionJS = new Insertion() if $(‘.insertions.show’).length > 0 console.log(“insertions.show”) insertionJS.showJS() …..continue

如何在侧边栏中停止双重渲染?

代码是双重渲染,如下所示: 什么时候应该只列出一次: Ran 1 miles Apr Journal 1 days Apr 视图/布局/ _stats.html.erb <div class="”> <span class="”> application_controller def set_stats @averaged_quantifieds = current_user.quantifieds.averaged if current_user @instance_quantifieds = current_user.quantifieds.instance if current_user end 结果是Quantifieds的nested_attribute。 quantifieds_controller class QuantifiedsController < ApplicationController before_action :set_quantified, only: [:show, :edit, :update, :destroy] before_action :logged_in_user, only: [:create, :destroy] def index if params[:tag] @quantifieds = Quantified.tagged_with(params[:tag]) […]

控制器和动作中定义的路径被忽略,Ruby on Rails

根据http://guides.rubyonrails.org/layouts_and_rendering.html 我应该能够在我的micropostscontroller中的创建操作中定义来自不同控制器的路径: def create @micropost = current_user.microposts.build(params[:micropost]) if @micropost.save flash[:success] = “Micropost created!” redirect_to profile_path else render ‘static_pages/profile’ end end 但是,当我创建post失败时(将其留空或使其太长),将呈现页面’/ microposts’,即控制器不存在的主页。 当我成功创建微博时,我被重定向到配置文件路径’/ profile’,当我将render ‘static_pages/profile’更改为redirect_to profile_path ,重定向工作。 为什么浏览器会忽略渲染请求并进入微博控制器主页? 此外,渲染的微博页面提供NoMethodError: NoMethodError in Microposts#create undefined method `name’ for nil:NilClass app/views/static_pages/profile.html.erb:16:in `_app_views_static_pages_profile_html_erb___1610169404003779010_70327969935820′ app/controllers/microposts_controller.rb:10:in `create’ 当重定向到配置文件时,配置文件可以自行呈现,因为在static_pages控制器中的配置文件操作中定义了@user。 @user = User.find_by_remember_token(cookies[:remember_token])

Ruby on Rails Ajax调用运行控制器代码,返回成功,但不渲染视图

我的页面上有一个工作搜索机制; 带有文本字段和“搜索”标记的提交按钮的表单。 我的页面上还有一个基于raphael.js的动画项目,上面有可点击的项目,我想要执行搜索。 点击后,我发送给我的控制器params数据,这些数据是从raphael对象中获取的搜索项。 正在传递数据,并且控制器代码运行,但相应的视图无法呈现,因此单击对用户显示为什么都不做。 所以点击后,我就像这样做一个Ajax调用: 文件searchthing.js // Add a search function circle.click(function (e) { var csrch = this.data(‘label’); // alert(‘clicked ‘ + csrch); e.preventDefault(); $.ajax({ type: “GET”, url: “/bubbleBar”, data: $.param({ srchterm: csrch} ), success: function(){ // window.location.replace(“/pictures”); }, error: function(XMLHttpRequest, textStatus, errorThrown) { alert(“— error: ” + errorThrown); } }); }); 我的控制器中的’bubbleBar’操作成功触发,传输搜索条件,并重定向到处理搜索的工作索引操作: 文件myController.rb: […]

Rails 3全局渲染

有没有办法告诉整个控制器呈现特定的部分或文本? 例: class PageNotesController “Testing” def index @notes = PageNotes.all end def show @note = PageNotes.find(params[:id]) end def create @note = PageNotes.create(params[:note]) end end 现在显然我可以进入每个单独的方法并告诉它渲染一些东西,但我只是想知道这是否可行。 提前致谢!

类`ActionView :: Base’的未定义方法`render’

当我启动应用程序崩溃后出现错误 /home/stereodenis/.rvm/gems/ruby-1.9.3-p194@nyanya/gems/haml-3.1.6/lib/haml/helpers/action_view_mods.rb:15:in `alias_method’: undefined method `render’ for class `ActionView::Base’ (NameError) 可能有什么不对? 完整跟踪https://gist.github.com/5e3244d488068c9d0ba7

Respond_to并重定向Rails中的相同操作

在Rails控制器的Update操作中,通常会有如下代码: def update @book = Book.find(params[:id]) if @book.update_attributes(params[:book]) redirect_to(@book) else render :edit end end 在else的情况下,这将呈现编辑模板。 但是,如果我想使用respond_to,与编辑操作中的方式完全相同,如下所示: def update @book = Book.find(params[:id]) if @book.update_attributes(params[:book]) redirect_to(@book) else respond_to do |format| format.html # edit.html.erb format.json { render :json => @team } end end end 因此,如果更新失败,请确保根据请求的格式返回json或html。 这有道理吗? 如果是这样,你将如何避免错误:“在此操作中多次调用渲染和/或重定向”