ruby-on-rails-3

Rails 3 controller from plugin

梦想与她 提交于 2020-01-03 16:01:49
问题 I am creating a Rails 3 plugin and I want to integrate controllers in it that will be automaticly consider by rails as a "normal" controller from the app/controllers folder. How can I do that or what is the best solution for me to have custom controllers from a plugin? I have found documentations from guides.rubyonrails.org but they have changed the documentation and plugin development doesn't include controllers anymore. Thanks 回答1: You will need to define a class within your plugin that

Rails3 CSV putting "" instead of actual quotes

狂风中的少年 提交于 2020-01-03 15:34:14
问题 Similar to this question except I don't use html_safe anywhere in the whole project. I generate a CSV file in index.csv.erb like this: <%= response.content_type = 'application/octet-stream' CSV.generate do |csv| @persons.each do |person| csv << [ person[:name], person[:nickname] ] end end %> PROBLEM: If nickname is NULL in the database (ActiveRecord/MySQL) then the CSV file associated element becomes "" . I would expect "" , or even nothing at all. Result file sample: Nicolas, Nico Joe, ""

ActiveAdmin how to add a custom controller without model [duplicate]

独自空忆成欢 提交于 2020-01-03 14:48:33
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: Add page to active admin I currently looking to a solution for adding a controller without a model to the admin generate by ActiveAdmin (and Rails 3.1). Of course I'd like to add a new menu in the navbar. Using ActiveAdmin.register MyControllerWithoutModel do isn't working. Edit : This question is a duplicate of Add page to active admin but no answer found. 回答1: This is what worked for me, just substitute the

Correct way of prevent duplicate records in Rails

对着背影说爱祢 提交于 2020-01-03 14:15:47
问题 In my model I have this: validates :name, :presence => true, :uniqueness => true In my controller I have: ... if @location.save format.html { redirect_to @location, :notice => 'Location was successfully created.' } format.json { render :json => @location, :status => :created } ... which successfully creates a record if there isn't already a record with this name in the table. I think it's good practice to check before inserting a possibly duplicate record instead of relying on the DB

Correct way of prevent duplicate records in Rails

折月煮酒 提交于 2020-01-03 14:14:51
问题 In my model I have this: validates :name, :presence => true, :uniqueness => true In my controller I have: ... if @location.save format.html { redirect_to @location, :notice => 'Location was successfully created.' } format.json { render :json => @location, :status => :created } ... which successfully creates a record if there isn't already a record with this name in the table. I think it's good practice to check before inserting a possibly duplicate record instead of relying on the DB

Getting Rspec + autotest working on windows

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-03 13:59:15
问题 I have installed growl + rspec + autotest on my windows 7 machine. From the command prompt, when I type 'rspec spec/' it doesn't work. The tests will only run if I use 'rake spec/' + 'autotest'. Also, I am running these tests: http://railstutorial.org/chapters/static-pages#code:default_pages_controller_spec (i.e. very, very trivial) and they are taking 8.11 seconds. They also fail when I run them - even though they don't in the example. I have done everything the tutorial told me, the problem

ActiveRecord - select first record from each group

天大地大妈咪最大 提交于 2020-01-03 13:35:12
问题 I want most recent message sent by each users. Here is sample data Table : conversations sender receiver message date ============================================================ 1 2 "hi" "2013-03-04 09:55:01.122074" 2 1 "hello" "2013-03-04 09:55:32.903975" 1 2 "have you done with the taks?" "2013-03-04 09:57:46.383007" 2 1 "almost..." "2013-03-04 09:58:55.783219" 2 1 "should be able to finish 2day" "2013-03-04 09:59:28.950705" 2 3 "shall we start?" "2013-03-04 10:01:16.842725" 3 2 "give me a

Rails3 and Sass::Plugin::options

丶灬走出姿态 提交于 2020-01-03 12:58:33
问题 When I try to add Sass::Plugin.options[:style] = :compact to environment.rb When I try to start up my server I get: uninitialized constant Sass (NameError) I have added gem 'haml', '3.0.0' to my Gemfile . Anybody ran into this? 回答1: I tried what you described and it worked fine for me. I'm using haml 3.0.4 which is the latest version. You may want to run a gem update haml on your system and try again. The list of changes from 3.0.0 to 3.0.4 are at http://sass-lang.com/docs/yardoc/file.SASS

How to share activerecord models via Ruby Gem

筅森魡賤 提交于 2020-01-03 12:35:25
问题 I have a couple of Rails project which have some codebase in common. The common code consists of some ActiveRecord Models and an api on top of that. Currently I am duplicating the common code in all projects which is a very bad practice. Now I want to move the common code to a Ruby Gem. I am new to Ruby on Rails. I have looked at several Gem tutorials but could not find anything useful that will help me create a gem with reusable ActiveRecord models. Essentially I want is that - Gem contains

How to share activerecord models via Ruby Gem

廉价感情. 提交于 2020-01-03 12:35:04
问题 I have a couple of Rails project which have some codebase in common. The common code consists of some ActiveRecord Models and an api on top of that. Currently I am duplicating the common code in all projects which is a very bad practice. Now I want to move the common code to a Ruby Gem. I am new to Ruby on Rails. I have looked at several Gem tutorials but could not find anything useful that will help me create a gem with reusable ActiveRecord models. Essentially I want is that - Gem contains