Ruby on rails 3 Where do I put Sinatra files intended to be embedded in a Rails3 app?

I want to use the new Rails3 feature that allows you to embed a Sinatra app inside rails. In my routes file, I have: # app names changed to protect the (not so) innocent MyApp::Application.routes.draw do match "/service", :to => MyService ... end And in /lib/my_service.rb I have class MyService < Sinatra::Base get "/" do "Hello World" end end When I try to start the Rails server I get Uninitialized constant MyService (NameError), which I suspect means my Sinatra file is

Ruby on rails 3 polymorphic rails association fails on inherited class?

I'm having trouble doing the reverse polymorphic association when I have an inherited class. Anyone know what's going on? ruby-1.9.2-rc2 > Label.first => #<Label id: 1, owner_id: 1, owner_type: "Student", name: "Lorem", created_at: "2011-01-23 05:02:29", updated_at: "2011-01-23 05:02:29"> ruby-1.9.2-rc2 > Label.first.owner => #<Student id: 1, email: "alice1@example.com", ..., avatar_updated_at: nil> ruby-1.9.2-rc2 > Label.first.owner.labels => [] class Stu

Ruby on rails 3 How to call model method when defining CanCan abilitry?

I have a problem using a method defined on a model in CanCan abilities: model def Car def can_paint? ..some conditions, return true or false.. end end ability can :paint, Car, :user_id => user.id, Car.can_paint? CarsController def paint @car = ..find the car.. return redirect_to jobs_path unless can? :paint, @car ... end error occurs when the paint action is called /.../app/models/ability.rb:11: syntax error, unexpected '\n', expecting tASSOC #error poi

Ruby on rails 3 Nested categories with mongoid

I have mongoid model with some entries and want to organize them into categories. Categories should have an option to ne nested like this: Videos: -Car video -Gadgets Video --iPad --Android Music: -Pop --Madonna -Rap --2pac --50cent How can I do it with mongoid? The order of categories does not matter.

Ruby on rails 3 Rails 3 replacement for verify

I am new to rails but was reading the docs about verifying params in my controllers and they seem to reference the verify method. But in rails 3 it shows that verify is deprecated. What is the new way of doing this? The error i am getting is: verify was removed from Rails and is now available as a plugin. Is this still used but just in plugin form now or have they replaced it with another method?

Ruby on rails 3 Thinking Sphinx - complicated sort on two fields

I am using thinking sphinx for search. Now I need to order my search results by two fields. The complicated part starts with this: "if date_approved is not null use it, else use created_at date for sorting the results in descending order" I implement this without thinking sphinx as : @model_values=Model.find(:all, :conditions => {:name => :johndoe}, :select => "*,if(date_approved,date_approved,created_at) as my_date",

Ruby on rails 3 Testing member routes of a resources in rails3 with rspec

I'm creating an application that will allow the user to take an exam. The exam object has_many questions and I want the user to take the exam in two parts. In order to implement this workflow, I've created the following routes in config/routes.rb: resources :exam do member do get 'get_part1' put 'put_part1' get 'get_part2' put 'put_part2' end end So, when the user issues GET /exam/:id/get_part1 they are shown the first set of questions, etc... I have all of this working an

Ruby on rails 3 Turn off CSRF token in rails 3

I have a rails app that serves some APIs to an iPhone application. I want to be able to simply post on a resource without minding on get the correct CSRF token. I tried some methods that I see here in stackoverflow but it seems they no longer work on rails 3. Thank you for helping me.

Ruby on rails 3 Checking data in the form not be empty

in the view (form) I check the data to be not blank (empty in php:)) but what I am doing is ugly: <% if request.post? %> <% if @ticket[:name].blank? %> <% style="fieldWithErrors" %> <% else %> <% style="field" %> <% end %> <% if @ticket[:department_id].blank? %> <% style1="fieldWithErrors" %> <% else %> <% style1="field" %> <% end %> <% else %> <% style=" " %> <% style1=" " %> <% end %> as default the st

Ruby on rails 3 Factory_girl and Factory_girl_rails conflict error

The following is the error message running rspec spec: /factory_girl-2.1.0/lib/factory_girl/registry.rb:38:in `add_as': Already defined: user (FactoryGirl::DuplicateDefinitionError) There are both factory_girl (2.1.0) and factory_girl_rails (1.2.0) installed. This error message disappears if factory_girl 2.1.0 is removed (caused another error of undefined method though). However the same setup has no problem running on another laptop with rspec. Here is part of the output of bundle show comma

Ruby on rails 3 Selectbox with Timezones in Rails 3.1

I want to make selectbox like this with simple_form (but it doesn't matter I think). I found that in Rails 2.1 was object TimeZone.us_zones but now it doesn't work neither Time.zone.all or smth. The line example for simple_form: = f.time_zone :time_zone, TimeZone.us_zones And I should have a time_zone field string format in db sqlite?

Ruby on rails 3 Rails 3.1 Remote Button Unobtrusive Javascript event not caught (JQuery)

I want to start using the Ajax events ajax:success, ajax:failure, ajax:complete and ajax:beforeSend as recommended for unobtrusive Javascript in posts like: http://www.simonecarletti.com/blog/2010/06/unobtrusive-javascript-in-rails-3/ http://www.alfajango.com/blog/rails-3-remote-links-and-forms/ But for some reason it's not working for me. I am missing something (something small) as I cannot get the events to trigger my Javascript. I am hoping someone could spot the "obvious" mistake/omissio

Ruby on rails 3 Altering nested messages helper from div to unordered list

I am using a helper method from ryan bates railscasts on ancestry to display nested messages(code below works perfectly). def nested_messages(messages) messages.map do |message, sub_messages| render(message) + content_tag(:div, nested_messages(sub_messages), :class => "nested_messages") end.join.html_safe end The above bit of code nests the individual divs in a tree like structure. I would like to make this into an unordered list, so what i have done is this: def nested_messages(m

Ruby on rails 3 Rails 3 link_to partial structure

I want to create a link_to render :partial. I have two partials stored already in the view folder in which I call the link_to (which is the profiles views). Getting the JavaScript to load the data is the next step but I am having trouble structuring the link_to properly. Here's what I had: <ul id="infoContainer"> <li><%= link_to render(:partial => "about") do %>About<% end %></li> <li><%= link_to render(:partial => "other") do %>Other<% en

Ruby on rails 3 Rails 3 - Ancestry gem method arrange not working

hi people I've follow this tutorial: http://railscasts.com/episodes/262-trees-with-ancestry when I tried to make the "arrange (:order => :id)" I got this message undefined method `arrange' for #<Array:0x8c19780> Extracted source (around line #4): 1: 2: <h1>Listing categories</h1> 3: 4: <%= nested_categories @categories.arrange(:order => :id) %> 5: 6: <br /> 7: Can you help me, please? Thanks!

Ruby on rails 3 Is there any open source topic-based subscriber/publish web service for SMS and email notifications?

I have the following requirement for my rails application. My users will subscribe for updates by choosing different categories and their preferences of receiving the updates (SMS or Email). They receive the updates according to their preferences when ever a update is posted on a particular category. I am planning to implement a web service with the above functionality. The web service will Expose an API to subscribe users for different categories. Expose an API to post updates to a particu

Ruby on rails 3 Heroku rake db:migrate doesn't work

Ruby 1.9.2 Rails 3.1 After the day of fighting with heroku issues I was able to finally have the command 'git push heroku master to work properly'. Gemfile has proper enties and pg gem is installed group :production do gem 'pg' end group :development, :test do gem 'sqlite3' end At this point application has been uploaded and start page can be viewed here http://growing-day-7939.heroku.com/ The next step should be migrating the database to the heroku with 'heroku rake db:migrate" and i

Ruby on rails 3 Getting error while starting server in Aptana3, RoR

I'm afraid that I have a bit silly question, but I wasn't able to solve this problem myself: alex@ALFA:~/Aptana Studio 3 Workspace/rails-test$ rails server => Booting WEBrick => Rails 3.1.3 application starting in development on http://0.0.0.0:3000 => Call with -d to detach => Ctrl-C to shutdown server Exiting /var/lib/gems/1.8/gems/activesupport-3.1.3/lib/active_support/dependencies.rb:234:in `load': /home/alex/Aptana Studio 3 Workspace/rails-test/config/initializers/session_ store

Ruby on rails 3 What is preventing this observer before_save from working properly?

I've created an Observer for the User class (below). I know the before_save method is getting called, and I know that the new_record condition is being entered, however the new record is never saved...am I missing something fundamental to the before_save callback? The save in the controller looks like (the error count produced by the puts is zero): def create @user = User.new(params[:user]) if @user.save #UserMailer.registration_confirmation(@user).deliver redirect_to root

Ruby on rails 3 How to check if the current user ID is present (once) in various instances of a model?

I have four models: Post, Comment, Vote, User (Devise). Users can vote posts and comments. The Vote model has an attribute called user_id where the ID of the user who voted the post or comment is stored. So as users vote, the structure looks like this: Post (:id = 29) Vote (:user_id = 1), Vote (:user_id = 3), Vote (:user_id = 5), Vote (:user_id = 2) 4 votes (@post.votes.count) I would like to have the following: If the current_user ID is present in the user_id attribute of the

Ruby on rails 3 CanCan error in Rails 3 app - ArgumentError wrong number of arguments (2 for 1)

I'm attempting to get CanCan working for a few specific actions in my Rails 3 app. I've defined my roles in the Ability.rb class, but something is causing an error in both production and development. Specifically, when I call can? to show/hide a link depending on User role I get the following: ArgumentError in Higher_eds#show Showing /Users/me/Desktop/myapp/app/views/higher_eds/_logged_in.html.erb where line #62 raised: wrong number of arguments (2 for 1) Can anyone help me figure out what'

Ruby on rails 3 Paperclip - rename file before saving

I use this method for renaming the image before the saving: def rename_avatar self.avatar.instance_write :file_name, Time.now.to_i.to_s end before_post_process :rename_avatar The image is renamed by the current time, but there's not added the file type, instead of 1334487964.jpg is saved only 1334487964.. What I missing there? I thought :file_name contains only the file name - without the file type

Ruby on rails 3 Rails 3.2 using content_tag to generate a 'Delete' button with twitter-bootstrap icons

I'm trying to replicate the Delete button icon in this example using the Rails 3 content_tag method, within a nested form and using jQuery unobtrusively (or at least I hope to be). Twitter-Bootstrap Delete Button icon (example) The html produced in when inspecting with Firebug is below. <a class="btn btn-danger" href="#"> <i class="icon-trash icon-white"></i> Delete </a> I'm using the following to generate the button with an icon but can

Ruby on rails 3 Multiple (n) identical nested forms generated square-times(n*n) when validation fails

User has two addresses shipping(:address_type=0) and billing(:address_type=1) User form with 2 classic nested forms for each address type are generated square times every submit and failed validation. Models: class User < ActiveRecord::Base has_many :addresses, :dependent => :destroy accepts_nested_attributes_for :addresses validates_associated :addresses end class Address < ActiveRecord::Base belongs_to :user validates :user, :address_type, :first_name, :last_n

Ruby on rails 3 Adding a unique ID to haml list item

I had the following line of code: %li= link_to "Home", main_app.root_path I now wish to include an ID for automation testing purposes to the minibar item but am unsure how to go about this, I have tried the following: %li(id = "minibar_home")= link_to "Home", main_app.root_path But the ID does not seem to be added when inspecting this through firebug or view source. Can you help?

Ruby on rails 3 Best way to support users sending profile pictures from mobile devices in a rails 3.0 app?

We are using carrierwave in a Rails 3 app and it works great! However, on our mobile site the button to select a file is grayed out. I've read that an iPhone will not grant access to files from a browser. Is Picup my only option for iPhone? It would be great if there was a solution that worked for Android and other devices as well. UPDATE: I realize that many (most?) mobile devices do not give access to files. Trying to find the most effective way to email images.

Ruby on rails 3 Trying to write a "points" system in my Rails 3 app

Rails 3.2.3 I'm trying to add a "points" functionality to my Rails app. The idea is pretty straight forward, if you click UP your points will increase by 1. if you click DOWN your points will decrease by 1. But for some reason the points do not change and each new links I create the points increase by 10. I have the points defaulting to 0 in my migration file (but they never show zero) t.column :points, :integer, :default => 0` here is part of my view code <td> <%= link_to "U

Ruby on rails 3 FactoryGirl + RSpec + Rails 3 Engine 'undefined method'

I have been trying to use FactoryGirl while developing a Rails 3 mountable engine, and when the factory is called in the spec, it returns the following error: NoMethodError: undefined method `foo_bar=' for #<Foo::Baz:0x007fed6e3e2700> Models Foo::Bar module Foo class Bar < ActiveRecord::Base has_many :bazs end end Foo::Baz module Foo class Baz < ActiveRecord::Base belongs_to :bar end end Factories FactoryGirl.define do factory :foo_bar, class: Foo::Bar do

Ruby on rails 3 Batch job in a rails app"

I have one situation I don't know how to solve... I have a rails app where I store device tokens to send push notifications to iOS devices. I have a control panel where I create a query to get the devices I want to notify, but the sending process will take some while, so how can I leave a process running in background or something like that?? What's the best way of doing this? Any idea? Thanks!

Ruby on rails 3 404 error on heroku db:push

I am getting a 404 error when trying to push my database to Heroku via Taps (1.9.2@[app_name]_db) heroku db:push --app [app_name] Loaded Taps v0.3.24 Auto-detected local database: sqlite://db/development.sqlite3 Warning: Data in the app '[app-name]' will be overwritten and will not be recoverable. ! WARNING: Destructive Action ! This command will affect the app: [app-name] ! To proceed, type "[app-name]" or re-run this command with --confirm [app-name] > [app-name] Sending sche

Ruby on rails 3 assets:precompile - permission denied - only on one computer

I have a rails app project folder which is on my dropbox folder. I work on 2 computers - home pc and a laptop (both win 7) If I do bundle exec rake assets:precompile on the pc it works fine and I see the line C:/Ruby193/bin/ruby.exe C:/Ruby193/bin/rake assets:precompile:all RAILS_ENV=production RAILS_GROUPS=assets mkdir -p H:/My Dropbox/project/public/assets cp -r C:/Ruby193/lib/ruby/gems/1.9.1/gems/tinymce-rails-3.5.7.1/vendor/assets/javascripts/tinymce H:/My Dropbox/project/public/assets

Ruby on rails 3 Rails 3 ActiveRecord Query questions

I've implemented "following" function. Showing "people user A is following" was simple, but showing "people who are following user A" is giving me troubles. I have follow_links, which have id, user_id, and follow_you_id column. When user A begins following user B, the columns will be like (user_id = A, follow_you_id = B). To show users that A(@user) is following, I can simply do @follow_yous = @user.follow_yous But I'm not sure how to show users who are following A(@user) To do this, I fir

Ruby on rails 3 Stanford Core NLP Gem error

I followed all instructions as given by https://github.com/louismullie/stanford-core-nlp and then installed JRE 1.6 as suggested in the attached article. But now am getting an error which says java.lang.NullPointerException Am new to Ruby and have tried in all places to get anwer on what is happening. actionpack (3.2.1) lib/action_controller/metal/rescue.rb:32:in rescue in process_action' actionpack (3.2.1) lib/action_controller/metal/rescue.rb:29:inprocess_action' actionpack (3.2.1) lib/ac

Ruby on rails 3 Texticle in rails isn't providing the responses I want. How configurable is it? or have I got it wrong?

I'm using the texticle gem in a Rails 3 app. I've got a table full of food names, such as Onion, Green Onion, Onion Powder, etc. etc. I'm searching the table with foodnames = FoodName.search(params[:search]) return render :json => foodnames when I attempt to search for 'chopped onion', I had hoped to get back a list of matching 'onion', as those are somewhat close, but I'm getting an empty set. If I use just 'Onion' or 'Onions', I get back the list I expected. there s

Ruby on rails 3 Delayed_job ActionMailer caching?

I currently call a delayed_job (gem delayed_job_mongoid) to send a confirmation email. However, it doesn't seem to use the latest data I'm passing, and instead uses a cached version. See below: My controller: ... _user.calculate_orders _user.save _user.reload Mailer.delay.order_reported(_user) ... The Mailer class Mailer < Devise::Mailer def order_reported(to_user) @to_user = to_user email_with_name = "#{@to_user.name} <#{@to_user.email}>" mail(:to => email_with_na

Ruby on rails 3 Rewriting SQL to ActiveRecord

I am trying to rewrite this old Rails 2 stuff such that it will work with Rails 3.2.1: Rails 2.2.2 query to rewrite B2bPrivilege.find_by_sql("SELECT b2b_privileges.*, vendors.name AS vendor_name FROM b2b_privileges LEFT JOIN vendors ON vendors.id = b2b_privileges.vendor_id WHERE b2b_user_id = ?", current_user_id) This is what I came up with and it creates the same SQL as seen in the Rails 2.2.2 example above but it doesn't bring in the vendors.name column into the stored result and I don't

Ruby on rails 3 Ruby on Rails - CanCan user is nil during destroy action

I'm getting cancan with devise wired into my first Ruby on Rails app. I have some of it working, but I hit a problem my newbie brain cannot seem to understand. I'm trying to delete a project model. The cancan ability.initialize call is not working because the user is passed as nil even though I am logged in and other calls successfully authorize In my show view, I have this link: <%= link_to "Purge this project", @project, method: :delete, data: {confirm: "There is no way to get it back.

Ruby on rails 3 Using Mongo Update and $set to insert field (throwing error)

Ok, this is probably a stupid question but I have been reading and trying different queries and for some reason I cannot get this to work without throwing an error. This is my first time working with MongoDB and it is in an RoR project. We set up charities to have a twitter handle field, but it was not put into the model originally. So we populated the DB with charities, but now none of them have the twitter handle field. I added it to the model so now all others created will have it. My issue

Ruby on rails 3 Polymorphic association data storage

Can someone explain how data is stored in polymorphic association. e.g., If I have comments, cases, case steps table. Comments table is link: belongs_to :user, class_name: 'User', foreign_key: 'user_id' belongs_to :commentable, polymorphic: true, counter_cache: true Cases table is link: has_many :comments, as: :commentable, dependent: :destroy Case steps table is like: belongs_to :case, class_name: 'Case', foreign_key: 'case_id' has_many :comments, as: :commentable, dependent:

Ruby on rails 3 rails3 view has_many :through attribute

Three models linked via has_many :through class Bozza < ActiveRecord::Base has_many :accessoryvolumes, :dependent => :destroy has_many :accessories, through: :accessoryvolumes belongs_to :lavorazione class Accessory < ActiveRecord::Base has_many :accessoryvolumes has_many :bozzas, through: :accessoryvolumes class Accessoryvolume < ActiveRecord::Base belongs_to :accessory belongs_to :bozza In the view for bozza, the attributes for bozza are accessible <% @bozza.

Ruby on rails 3 i am using the active admin gem.but it comes error like this couldn't find file 'jquery-ui'

source 'http://rubygems.org' gem 'rails', '3.1.0' # Bundle edge Rails instead: # gem 'rails', :git => 'git://github.com/rails/rails.git' gem 'mysql2' gem 'activeadmin' # Gems used only for assets and not required # in production environments by default. group :assets do gem 'sass-rails', " ~> 3.1.0" gem 'coffee-rails', "~> 3.1.0" gem 'uglifier' end gem 'jquery-rails'

  1    2   3   4   5   6  ... 下一页 最后一页 共 63 页