Tag: railcasts

在ajax请求中的rails中的Gettin 500内部服务器错误

我正在尝试从表单创建记录。 我使用railscast 136作为地面工作。 当我尝试提交时,我因缺少部分而得到500错误。 我已经创建了控制器相关的javascript视图,但它正在请求一个与模型同名的视图。 错误信息 渲染约会/ create.js.erb(3.8ms)在12ms内完成500内部服务器错误 ActionView :: Template :: Error(缺少部分约会/约会{:locale => [:en],:formats => [:js,:html],:handlers => [:erb,:builder,:coffee]搜索:*“/ Users / gjores / Sites / Rails / verkstad_test / app / views”):1:$(’#appointmentments’)。append(”) ; app / views / appointmentments / create.js.erb:1:在_app_views_appointments_create_js_erb___2325925946390315228_70273089113920′ app/controllers/appointments_controller.rb:16:in create’ 调节器 def create @appointment = Appointment.new(params[:appointment]) if @appointment.save respond_to do |format| format.html { […]

rails虚拟属性不会从form_for提交中读取

我正在尝试实现Ryan Bate的railscast#167中概述的rails标记模型。 http://railscasts.com/episodes/167-more-on-virtual-attributes 这是一个很棒的系统。 但是,我无法获取表单将tag_names提交给控制器。 tag_names的定义是: def tag_names @tag_names || tags.map(&:name).join(‘ ‘) end 不幸的是,在我的情况下,@ tag_names永远不会在表单提交上分配。 我无法弄清楚为什么。 所以它总是默认为tags.map(&:name).join(”)。 这意味着我无法创建文章,因为它们的tag_names不存在,我也无法在现有标签上编辑这些标签。 有人可以帮忙吗?

在创建图像之前使用jCrop与cloudinary through rails 4进行裁剪

我已经有一段时间了。 我正在使用cloudinary上传照片,并尝试使用jcrop在照片创建动作上实现裁剪function。在我实施cloudinary后,我在Jcrop上跟踪了railscast#182。我认为我在获取新的裁剪参数时遇到问题(x ,y,w,h)在保存图像之前返回上传器。 更新:我甚至没有将值放入f.text_fields。 当我移动裁剪器时,应该有新值吗? 这是一张空白字段的图片: 此外,当我提交照片时,现在我对裁剪适应性的转换发生了冲突!=裁剪 这是我的代码…… image_uploader.rb class ImageUploader [“profile pic”] process :convert => “jpg” version :thumbnail process :crop eager resize_to_fill(150, 150) cloudinary_transformation :quality => 80 end # For more options, see # http://cloudinary.com/documentation/rails_integration#carrierwave def crop if model.crop_x.present? resize_to_limit(400, 400) manipulate! do |img| x = model.crop_x.to_i y = model.crop_y.to_i w = model.crop_w.to_i h […]

rails excel mime-type – 如何更改默认文件名?

我按照http://railscasts.com/episodes/362-exporting-csv-and-excel进行操作,并在我的Rails应用程序中设置了Excel下载。 我的控制器代码如下所示: def show @project = Project.find(params[:id]) @project.tasks.order(:name) respond_to do |format| format.html format.json { render json: @project } format.xls end end 在我看来,我创建了下载excel文件的链接,如下所示: .dl_xls= link_to “Download xls”, url_for(:format => ‘xls’) 现在生成的excel文件总是被命名为Project记录的id,例如80.xls 有没有办法改变这种行为并给它一个自定义名称? 谢谢..

显示来自Rails应用程序的Twitter订阅源

我已经能够让用户通过OmniAuth登录Twitter(我遵循Railscast#235-6并制作了一个简单的应用程序)。 现在我正在尝试显示登录用户的Twitter提要。 谁能告诉我这是怎么做到的? 我如何初始化Twitter? 如何传入登录用户的用户名和密码? 我是Rails的新手,所以如果我确切地知道放置代码的位置会很有帮助。 谢谢

Railscast从头开始授权用户

所以这是我根据Railscast#386编写的授权代码。 问题是该块适用于除user_controller之外的所有控制器。 换句话说,任何用户都可以对任何其他用户进行triger edit和update操作,即使给予它的块与有利于edit和update操作的块相同。 def initialize(user) allow :users, [:new, :create, :show] allow :sessions, [:new, :create, :destroy] allow :favors, [:index, :show] if user allow :users, [:edit, :update] do |usr| usr.id == user.id end allow :favors, [:new, :create] allow :favors, [:edit, :update] do |favor| favor.user_id == user.id end allow :acceptances, [:create, :update] do |acceptance| !acceptance.has_accepted_acceptance? end end […]

Nokogiri分段故障?

我试图从Railscast运行一个简单的Ruby脚本,一旦我运行我的程序,我得到以下Segmentation fault bug错误。 我已经尝试卸载并重新安装Nokogiri和LibXML,但仍然没有。 无论如何修复Ruby 1.87版本? 也许这就是问题? $ ruby -v ruby 1.9.2p180 (2011-02-18 revision 30909) [x86_64-darwin10.7.0] /Users/da/.rvm/gems/ruby-1.9.2-p180/gems/nokogiri-1.4.4/lib/nokogiri/nokogiri.bundle: [BUG] Segmentation fault ruby 1.8.7 (2009-06-12 patchlevel 174) [universal-darwin10.0] Abort trap $ ruby -v ruby 1.9.2p180 (2011-02-18 revision 30909) [x86_64-darwin10.7.0] $ bundle exec nokogiri -v— — warnings: [] nokogiri: 1.4.4 ruby: version: 1.9.2 platform: x86_64-darwin10.7.0 engine: ruby libxml: […]

OmniAuth Railscast中的DangerousAttributeError教程:create由ActiveRecord定义

我在SO上查看了ActiveRecord :: DangerousAttributeError和其他类似的线程,但它们没有解决同样的问题。 我正在关注omniauth教程: http ://railscasts.com/episodes/235-omniauth-part-1?view = ascicast 我可以通过oauth通过Twitter进行身份validation并返回用户的数据(auth)。 问题是由于此错误消息,我无法在数据库(sqlite3)中创建/保存它。 错误: ActiveRecord::DangerousAttributeError in AuthenticationsController#create create is defined by ActiveRecord Rails.root: /beta/devise-omniauth1 Application Trace | Framework Trace | Full Trace app/controllers/authentications_controller.rb:15:in `create’ Authentications_Controller: def create auth = request.env[“omniauth.auth”] current_user.authentications.create(:provider => auth[‘provider’], :uid => auth[‘uid’]) flash[:notice] = “Authentication successful.” redirect_to authentications_url end 楷模: class Authentication < ActiveRecord::Base […]

如何使用私人提交来隐藏个人资料?

当用户通过private提交时,我们如何隐藏来自Feed的提交信息以及能够在其公开个人资料中看到它的其他用户? … … 我们将下面的内容放在控制器中,但由于私有按钮将包含许多不同的_forms,我是否必须将它放在每个控制器中,还是可以将它放在应用程序控制器中? if params[:private] # the private action / What do we need to put here? else # normal submit / and here? 我跟着这个铁路播放节目几乎到了T来构建活动源: http ://railscasts.com/episodes/406-public-activity。 以下是公开个人资料的代码: users_controller.rb def show @user = User.find(params[:id]) @habits = @user.habits @valuations = @user.valuations @accomplished_goals = @user.goals.accomplished @unaccomplished_goals = @user.goals.unaccomplished @averaged_quantifieds = @user.quantifieds.averaged @instance_quantifieds = @user.quantifieds.instance end show.html.erb […]

Rails 4中动态表单的未允许参数

我是Rails的新手并基于此构建了一些东西 http://railscasts.com/episodes/403-dynamic-forms 但我在附加字段中存储数据时遇到问题…我有一个ProductType对象,它有许多ProductField对象。 ProductField对象也属于ProductType,Product对象属于ProductType。 因此,可以通过构造函数ProductType轻松添加新的动态字段,但是当我尝试通过Product控件在此字段中设置数据时,没有任何反应。 我确信这个问题与使用强参数有关,但是这里描述的修复和这里没有帮助。 product.rb class Product < ActiveRecord::Base belongs_to :product_type serialize :properties, Hash end product_type.rb class ProductType < ActiveRecord::Base has_many :fields, class_name: "ProductField" accepts_nested_attributes_for :fields, allow_destroy: true end product_field.rb class ProductField < ActiveRecord::Base belongs_to :product_type end products_controller.rb class ProductsController []}) end product_type_controller.rb class ProductTypesController < ApplicationController def product_type_params params.require(:product_type).permit(:name, fields_attributes: [:id, :name, […]