ruby-on-rails-3.2

How to use dependent: :destroy in rails?

我是研究僧i 提交于 2019-12-17 18:16:02
问题 I have 2 models as describes below. class EmpGroup < ActiveRecord::Base belongs_to :user has_many :emp_group_members, dependent: :destroy end and class EmpGroupMember < ActiveRecord::Base belongs_to :emp_group belongs_to :user end now the problem is whenever I tried to destroy a group then I received a error as below. PG::ForeignKeyViolation: ERROR: update or delete on table "emp_groups" violates foreign key constraint "fk_rails_bd68440021" on table "emp_group_members" DETAIL: Key (id)=(1) is

TinyMCE 4 links plugin modal in not editable

风格不统一 提交于 2019-12-17 17:54:46
问题 I am using tinyMCE4 editor inside a Boostrap modal dialog. when I clicked on link icon it opens a new modal dialog box, It displayed fine but the input areas are not editable. <div id="editing" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"> <form> <label> <span>Description</span> <div id="description"></div> </label> <form> </div> <script> tinymce.init({ selector: 'div#description', inline: false, theme : "modern", schema: "html5", add

Rendering JSON in controller

限于喜欢 提交于 2019-12-17 17:24:55
问题 I was reading a book and in a chapter about Controllers when it talks about rendering stuff, for JSON it has an example like this but doesn't go in to details so I couldn't figure out the bigger picture that this example fits in: render :json => @projects, :include => tasks And also some example with JSONP using it with callback functions: render :json => @record, :callback => 'updateRecordDisplay' Can someone explain these? 回答1: You'll normally be returning JSON either because: A) You are

Server is already running in Rails

纵饮孤独 提交于 2019-12-17 15:02:42
问题 When I am starting rails server using rails s command it is showing A server is already running. Check C:/Sites/folder/Pids/Server.pids When I open the file it is outputting a 4 digit number only so how could I resolve this issue ? FYI No other instance of Rails cmd is running this time. Checked Task manager but only cmd.exe is showing no else process is running. (using Windows). 回答1: Remove the file: C:/Sites/folder/Pids/Server.pids Explanation In UNIX land at least we usually track the

How force that session is loaded?

故事扮演 提交于 2019-12-17 11:46:11
问题 I'm working on an application that needs to use session id information. My session is stored in cookies. The problem I have is that my session is not immediately available to the controller when a user comes to the site for the first time. I think I may be missing something about how sessions are initialized in Rails. But I'm positve about the fact that the session is not loaded because this is the output of session.inspect : #<Rack::Session::Abstract::SessionHash:0x15cb970 not yet loaded>

How force that session is loaded?

只愿长相守 提交于 2019-12-17 11:45:32
问题 I'm working on an application that needs to use session id information. My session is stored in cookies. The problem I have is that my session is not immediately available to the controller when a user comes to the site for the first time. I think I may be missing something about how sessions are initialized in Rails. But I'm positve about the fact that the session is not loaded because this is the output of session.inspect : #<Rack::Session::Abstract::SessionHash:0x15cb970 not yet loaded>

How to set defaults for ransack sorting?

牧云@^-^@ 提交于 2019-12-14 04:16:38
问题 To put simply enough, I'd just like to know if there's a way to set defaults for the sorting functionality using the Ransack gem? ie. Currently, I have the following when the page loads: But instead, I'd like to have the following defaults when the page loads: Is it possible to do this via proper configuration of the Ransack Gem? Thanks in advance as always! Best Regards! 回答1: This works for me: @search = Change.search(params[:q]) @search.sorts = 'updated_at desc' if @search.sorts.empty? Note

Translating custom error messages

时光毁灭记忆、已成空白 提交于 2019-12-14 04:00:33
问题 I have a form (using simple_form) which I want to implement support for translated error messages. All my translations appear with the exception of the error message. My Customer model is: class Customer < ActiveRecord::Base attr_accessible :name, :phone, :email, :contact_method validates_presence_of :phone, :email, :contact_method, :message => I18n.t(:required) end My fr.yml file fr: name: 'Nom' phone: 'Téléphone' email: 'Courriel' contact_method: 'Méthode de contact' required: 'Requis' My

Should Rails uglifier uglify (mangle) function names?

不羁的心 提交于 2019-12-14 03:47:38
问题 My .js files are compressed and variables mangled, but function names are not mangled (running latest Rails 3.2.8 and latest uglify 1.3.0 gem) on Heroku. According to https://github.com/lautis/uglifier#usage the "mangle" option defaults to true. Below is my config. From production.rb: config.assets.compress = true config.assets.js_compressor = :uglifier I've also tried config.assets.compress = true config.assets.js_compressor = Uglifier.new(:mangle => true, :toplevel => true, :copyright =>

Rails 3 prototype render :update response has text/html content-type

让人想犯罪 __ 提交于 2019-12-14 03:47:33
问题 I'm trying to get some RJS code written with prototype and Rails 2.3.11 to work in Rails 3.2.1 I have the prototype-rails gem, so render :update do |page| works, I'm using a form with :remote => true that sends an ajax request to the controller, and the javascript looks like it's being generated ok. However, the content-type in the header of the response is text/html; charset=utf-8 , which should be text/javascript . In the controller I'm calling it like this: render :update do |page| if