ruby-on-rails-3.1

How can I keep my initializer configuration from being lost in development mode?

核能气质少年 提交于 2019-12-03 22:36:25
I'm working on a Rails app that uses an engine. I'm using an initializer to configure one of my engine's controllers so that it will trigger an action in the host app. The code looks something like this: # config/initializers/my_engine.rb MyEngine::SomeController.after_filter proc { # Do something in the host app }, :only => :update This works fine in production, but in development mode, the proc is only called on the first request. This is because the classes are getting reloaded and this configuration is lost, because it was stored in a class variable. (For example, MyEngine::SomeController

Rails javascript database queries

别说谁变了你拦得住时间么 提交于 2019-12-03 21:56:52
How do I do a PUT, POST or DELETE call from javascript? I've collected some data using jquery drag and drop. How do I then send this to the database? I think I might be able to use jQuery.ajax but can't work out how exactly. Any pointers appreciated. Solution: This is the javascript that works $(document).ready(function() { $.ajax({ type: "PUT", url: "/articles/8", // should be mapped in routes.rb data: {articles:{name:"New Name"}} }); }); But it doesn't change the name of article 8 to New Name. Firebug shows no errors, but I still can't pass data to the edit. The url is the standard update

Rails search functionality

我是研究僧i 提交于 2019-12-03 21:55:46
I am taking a rails class at my University and I am trying to create a search form which will show the results on the same page rather than show a different page of results. Is this something simple to do? I am creating a museum app with artifacts for each museum but I want the user to search artifacts from either page. On my routes.rb I have resources :artifacts do collection do get 'search' end end On my museum index I have the code below that he gave us but not sure how to tweak the get routes for the same page. <%= form_tag search_artifacts_path, :method => 'get' do %> <p> <%= text_field

error precompiling assets when moving to production

帅比萌擦擦* 提交于 2019-12-03 21:43:57
I am trying to move my project to production, trying to RAILS_ENV=production bundle exec rake assets:precompile gives me an error, without specifying in which file it is. rake aborted! Sass::SyntaxError: Invalid CSS after "}": expected selector or at-rule, was "}" (sass):89 /Users/mac/.rvm/gems/ruby-2.2.3/gems/sass-3.4.23/lib/sass/scss/parser.rb:1207:in `expected' /Users/mac/.rvm/gems/ruby-2.2.3/gems/sass-3.4.23/lib/sass/scss/parser.rb:1137:in `expected' /Users/mac/.rvm/gems/ruby-2.2.3/gems/sass-3.4.23/lib/sass/scss/parser.rb:42:in `parse' /Users/mac/.rvm/gems/ruby-2.2.3/gems/sass-3.4.23/lib

Help to fix strange sqlite3 error - dyld: Library not loaded: /usr/lib/libsqlite3.0.dylib

有些话、适合烂在心里 提交于 2019-12-03 21:17:36
I am suddenly getting an sqlite3 error: ActionView::Template::Error (dyld: Library not loaded: /usr/lib/libsqlite3.0.dylib Referenced from: /System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/CFNetwork.framework/Versions/A/CFNetwork Reason: no suitable image found. Did find: /usr/lib/libsqlite3.0.dylib: mach-o, but wrong architecture /usr/local/lib/libsqlite3.0.dylib: mach-o, but wrong architecture /usr/lib/libsqlite3.0.dylib: mach-o, but wrong architecture I have no idea why I am suddenly getting this error. Rails 3.1.0 and Ruby 1.9.2 Mac OSX 10.5.8 Okay so this is a

How to make AJAX responses work from the Rails side?

半城伤御伤魂 提交于 2019-12-03 20:38:10
The HTML form: <form id="newsletter" method="post" action="/subscribers" data-remote="true"> <label for="email">Enter your email:</label> <input type="text" name="email" class="text" /> <p class="btn"><span>Signup</span></p> </form> Note the data-remote="true" The Controller: class SubscribersController < ApplicationController def create @subscriber = Subscriber.create(:email => params[:email], :ip_address => request.remote_ip ) respond_to do |format| format.js end end end The View (subscribers/create.js.erb) no clue what goes here to make it return normal AJAX response (or error if it

Heroku cedar, Rails 3.1rc6, subdomain routing

纵然是瞬间 提交于 2019-12-03 20:17:53
Locally, on Unicorn, my subdomain setup works fine. I've followed the heroku subdomain docs to the letter, and also the subdomains Railscast . subdomain.lvh.me:3000 points to the right place, and lvh.me:3000 points correctly to the root defined in routes.rb: root :to => "pages#home" However, in my new staging deployment on Heroku's Cedar stack, again using Unicorn, whilst subdomain.mydomain.co.uk points to the right place, mydomain.co.uk doesn't. Instead of going to pages#home as per the routes file, it's hitting the books controller, which it's only meant to do if there's a subdomain in the

How to add sequences to a migration and use them in a model?

你离开我真会死。 提交于 2019-12-03 19:47:26
问题 I want to have a " Customer " Model with a normal primary key and another column to store a custom "Customer Number". In addition, I want the db to handle default Customer Numbers. I think, defining a sequence is the best way to do that. I use PostgreSQL. Have a look at my migration: class CreateAccountsCustomers < ActiveRecord::Migration def up say "Creating sequenze for customer number starting at 1002" execute 'CREATE SEQUENCE customer_no_seq START 1002;' create_table :accounts_customers

scheduling a job every minute Rails 3.1 on Heroku

与世无争的帅哥 提交于 2019-12-03 19:32:52
问题 I want to run a task every minute on Heroku to check if conditions are met to time-out certain user tasks. I can only run a Heroku cron job every hour, so what's the best way to set up a timed task like this. I am using Rails 3.1 on Heroku. 回答1: You could use delayed_job with a self-restarting job with a :run_at . Something sort of like this: class YourJob def do_interesting_things #... Do what needs to be done. self.delay(:run_at => 1.minute.from_now).do_interesting_things end def self.start

Ruby on Rails 3.1 Blog Engines

ぐ巨炮叔叔 提交于 2019-12-03 17:23:07
问题 I see a lot of people asking about Blog Engines, but most of the questions & answers are rather old. Or if they aren't old most of the projects are old. I'm wondering if anyone knows of any Blog Engines that currently support Rails 3.1 or are at least being actively developed to support Rails 3.1. I would also be interested in seeing any sample applications or blog posts written for Rails 3.1 Blogs. I am going to be adding a blog to one of my websites, and would prefer to simply use a Rails