ruby-on-rails3

Rails 3, belongs_to, has one? For 3 models, Users, Instances, Books

I have the following models: Users (id, name, email, instance_id, etc...) Instances (id, domain name) Books (id, name, user_id, instance_id) In Rails 3, When a new book is created, I need the user_id, and instance_id to be populated based on the current_user. Currently, user_id is being assigned when I create a new book but not instanc...

Validating :inclusion in rails based on parent Model's attribute value

I have two models Project and 'Task` where project has_many tasks and task belongs to project Now in my Task model I am doing validation on a field using attributes in the project validates :effort, :inclusion => 1..(project.effort) This results in an error method_missing: undefined method project Question is, how can I validate a c...

belongs_to, can Rails 3, have 1+ foreign

Possible Duplicate: Rails 3, belongs_to, has one? For 3 models, Users, Instances, Books I have a book table (id, name, user_id, instance_id) both user_id and instance_id are foriegn keys. user_id belongs to instance_id. When a new book is created I need both user_id and instance_id assigned. Is that way to do that, in th...

the issue about rails 3 can't start the application on windows

I using the rails by Instantrails on windows.It can run well before I update the rails version to rails 3 . The error message is : E:\InstantRails-2.0-win\rails_apps\myproject>rails server E:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/bundler-1.0.0/lib/bundler/lo ckfile_parser.rb:48:in parse_source': undefined method[]' for nil:...

Can I attach a named scope to a link in Rails?

I have an events model which has two named scopes: class Event < ActiveRecord::Base scope :future, lambda { where('events.date >= ?', Time.zone.now) } scope :past, lambda { where('events.date <= ?', Time.zone.now) } end I call these scopes from my controller by creating two new controller actions (named "future" and "past"): My c...

Ruby on Rails 3 routing error

Am working my way thru Ruby on Rails Tutorial: Learn Rails by Example and am on this page: http://railstutorial.org/chapters/static-pages#top Am getting problems when I create an HTML page in the public directory which is called public/hello.html and should appear as in Figure 3.3. My problem is that when I try to create the page an...

Is a polymorphic association appropriate here?

Here's what I'm thinking: class Widget < ActiveRecord::Base has_one :widget_layout end class WidgetLayout < ActiveRecord::Base belongs_to :widget belongs_to :layoutable, :polymorphic => true end class InformationalLayout < WidgetLayout has_one :widget_layout, :as => :layoutable end class OneWayCommunicationLayout < WidgetLayo...

Passing paramters from rails views to jquery (gmap)

Hi I want to use this jquery plugin in my rails3 apps http://gmap.nurtext.de/ (Google Maps Plugin for jQuery) It seems very easy to use: $("#map").gMap({ markers: [{ latitude: 47.660937, longitude: 9.569803, zoom: 6 }); But i have a question, how i pass the values to this ...

Bunlder, Rails3: how to avoid git check of edge gems in :test group during deploying?

I have such lines in Gemfile: group :test do ... gem 'cucumber', :git => "git://github.com/aslakhellesoy/cucumber.git" ... end When I try do deploy on server via bundle install --deployment --quiet --without development test, I get an error: sh: git: command not found ** An error has occurred in git when running `git clone "g...

ujs link problem in rails3

hi I want to add a remote link via javascript(mootools). This code adds the link, but the click on this new link('delete foo 1') sends an html request and not an ajax request. Why doesn't it send an ajax request? Can anyone help me. Thanks <div id="add_link"> add link </div> <%= javascript_tag do %> $('add_link').addEvents({ 'cl...

resources :users, :as => 'members' equvalent in Rails 3

So in Rails2 you could setup a route like this: resources :users, :as => 'members' This way you still have your users_path but it matches /members Now, how do you go about doing this in Rails3? :as parameter here means totally different thing and I can't find what makes it work as before. ...

In Rails 3, respond_to and format.all works differently than Rails 2?

the code respond_to do |format| format.html format.json { render :json => @switches } format.xml { render :xml => @switches.to_xml } format.all { render :text => "only HTML, XML, and JSON format are supported at the moment." } end the above will work in Rails 2.2.2. But in Rails 3, getting controller/index.html or index on th...

Rails 3 Scaffolding, Adding Routes Question

Hello, rails 3 newbie, with a general question about adding an additional route after scaffolding. I create a scaffold for books... Which works great, and provides a nice index page. The Index page shows all books in the system, I'd like to add a page '/books/yours' that shows the books the user created. I already added the user_id to...

Show latest posts all from unique tags (Rails 3.0, Acts_As_Taggable_On)

tags_controller.rb: def index @title = "tags" @posts = Post.tag_counts.collect do |tag| Post.tagged_with(tag).first(:order => "updated_at DESC") end @posts.uniq! end tags/index.html.rb: <%= render 'latest' %> _latest.html.erb: <%- for post in @posts -%> <%- post.tags.each do |t| -%> <%= link_to t.name, tag_path(t...

What does this default RSpec statement mean?

User.should_receive(:update_attributes).with({'these' => 'params'}) What does that statement mean? these isn't instantiated anywhere as meaning anything. The whole statement is this : describe "with valid params" do it "updates the requested user" do User.should_receive(:find).with("37") { mock_user } User.should_re...

amazon-product-advertising-api gem + Rails 3

Does the amazon-product-advertsing-api gem work with rails 3? ...

Ruby on Rails 3 and Google Book Search

I'm trying to get started using the Google Data API for Google Book Search in my Ruby on Rails 3 application, and I don't even understand how to get started. What gems do I need? What do I need to do in order to do something simple like searching for books with a title of Foobar? ...

Syntax for link_to with block in rails3 with :remote=>true and including :class and :id

For the love of god, I've been banging my head on this for hours. Using rails3 rc, 1.9.2. I'm trying to create a link_to that submits an ajax request, with parameters, a class and id, and needs a block so I can insert a span tag around the name. Documentation is of absolutely zero help, as are numerous google searches. Here's what I've...

Why doesn't this partial render with UJS / jQuery?

I'm trying to use jQuery to create posts with a form in my Rails 3 project. Here's what I have: look below for updated results create.js.erb: $("#posts").prepend("#{render(:partial => 'posts')}"); layouts/application.html.erb: ... <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"&g...

RoR: Error when doing rake command db:create => rake aborted! no such file to load -- initializer

Hello, I just installed a fresh new version of Ubuntu 10.04 and wanted to get my rails projects working. I checked out a rails project 2.3.3 and fill in the databasye.yml file with the typical sqlite-settings: # SQLite version 3.x # gem install sqlite3-ruby (not necessary on OS X Leopard) development: adapter: sqlite3 database: d...