ruby-on-rails

Linking two tables together using has_many AND has_one?

I sure this has been asked a million times already. I just not searching very well. I have the following setup: I have an Instructor who has many Events. Each event has only one Instructor (owner/creator). I want to add a separate linkage to allow other instructors to be associated but still preserve the original instructor (owner). I ha...

Use accepts_nested_attributes_for to create new records or update existing.

Read the big update for the latest information. Hey everyone, I've got a many-to-many relationship in a rails app that involves three tables: a user table, an interests table, and a join user_interests table that also has a rating value so a user can rate each of their interests on a 1-10 scale. I am basically looking for a way for a ...

Learning how to spec..seem to be having troubles

Here's my code I'm spec'ing: def vote_up get_vote @vote.value += 1 unless @vote.value == 1 @vote.save respond_to do |format| format.js { render :action => "vote", :layout => false } end end Seems pretty straightforward. This is what I'm trying to spec it with : it "should vote up" do @mock_cat = Factory.create(:ca...

Usecase Diagrams with Rails

Hi, I want to generate usecase diagrams automatically from given actors and usecases when the user clicks a button. I am using Ruby on Rails on Netbeans IDE. Is there any plugin/gem or any other way to achieve this. ...

How to pass variables to render_to_string?

Trying to do the following @message = render_to_string ( :sender => sender, :template => "template" ) But when accessing @sender in template it turns out to be nil:NilClass. Double checked if I pass the right variable and it's totally fine. Maybe there are other way to pass variables to render_to_string? ...

complex arel query

I have a model where an article can have multiple tags (and a tag multiple articles). Article has two subclasses, product and kit. Products have a category, kits have not. How can I get all articles (both kits and products) of a certain tag (I know the tag.id) , with the product's category loaded (avoiding a n+1)? ...

close to messing up my db on heroku: mysql error on db:pull...

I think I am close to mess up my db on heroku I am trying to download the remote DB on heroku by heroku db:pull I get the following message: news_items: 100% |==========================================| Time: 00:00:01 /usr/lib/ruby/gems/1.8/gems/sequel-3.13.0/lib/sequel/adapters/mysql.rb:169:in `query': Mysql::Error: Duplicate entr...

In Rails, what is the difference using "has_many with belongs_to" vs "has_many with has_one"?

For example, in class Student < ActiveRecord::Base has_many :awards end class Awards < ActiveRecord::Base belongs_to :student end the above should be the correct usage, but what if we use class Student < ActiveRecord::Base has_many :awards end class Awards < ActiveRecord::Base has_one :student end doesn't the above also m...

Debugging Solr search queries on Sunspot

How can I debug Solr search queries when using the Sunspot gem on Rails? I have some queries that are returning bizarrely high scores, and I'm trying to get to the bottom of why this is happening. It doesn't seem like any debugging information is exposed to Sunspot, so I think that I need to debug through Solr directly. Fortunately, So...

Mongoid Object.all seems to return a lot of []

Why doesn't this work: ruby-1.8.7-p249 > List.create :search_terms => 'foo' => #<List _id: 4c9044a02249c7a5e2000001, search_terms: "foo", user_id: nil> ruby-1.8.7-p249 > List.all => #<Mongoid::Criteria:0x1030dea90 @klass=List, @documents=[], @selector={}, @options={}> ruby-1.8.7-p249 > List.all.documents => [] ...

How to use javascript_include_tag to get all scripts in a folder

Hi guys, I'd like to use javascript_include_tag to grab all view related scripts using recursion, which a placed in public/javascripts/views. I'm trying javascript_include_tag "/views", :recursive => true, but failed to add any script. Regards, Alexey Zakharov ...

Which is the best place to set title in Rails ?

Before Rails 3 I used to set a title instance variable in my controller actions and then use <%=@title%> in my layouts. But in Rails 3 they have included a helper method def title(page_title) @content_for_title = page_title.to_s end and in the application.html erb <title><%= yield(:title) %></title> This requires us ...

How to avoid Credit Card information being "saved" anywhere in a Rails app?

I've read some good information (on SO) about how you must avoid storing credit card information on your website. My Rails app would be the one getting the CC information from a on my website, correct? (as opposed to a payment processor site, if that's possible?) If so, then how do I know what all logs to "silence" so that they don't st...

How to automatically escape HTML in Ruby on Rails?

I'm just getting started with RoR (and web development in general).I know that when outputting user-supplied data we should escape it with the h() helper. Is there a way to ensure that all form data (params?) received by an action is guaranteed to be escaped automatically? (I do understand that it's a wise decision to escape HTML when di...

Resolved : How to set otherlang.yml as default for my ROR application

Hi , I am working on Internationalization . I have the otherlanguagefile.yml file for all the locales . By default my application takes en.yml . How could i set otherlanguagefile.yml as default. Edit : I have changed in my environment.rb file as config.i18n.default_locale = :otherlanguage it works fine.. ...

Why does my CSS go screwy "sometimes"

A website of mine is behaving weirdly. The layout sometimes is fine, and sometimes it is screwy. An example page that I see the problem on is this one: link Disclaimer: I have yet to start my investigation into cause in earnest. I am turning to Stackoverflow because I am lazy and I hope someone will say "That happened to me once, it is ...

Implementing STI where the parent class doesn't have a controller of its own its just a model and has a relationship with other models. Rails STI

I have the following scenario class XYZ < ActiveRecord::Base has_many :abcs end class ABC < ActiveRecord::Base belongs_to :xyz end class A < ABC end class B < ABC end class C < ABC end The model ABC doesn't have any controller, or view. Data related to ABC will be inserted from the XYZ views and controllers. The user sets a type v...

Ununderstandable Rails 3.0 log

Hi, since i migrated to rails 3.0, logs are now filled with queries like this: SQL (8.5ms) SELECT a.attname, format_type(a.atttypid, a.atttypmod), d.adsrc, a.attnotnull FROM pg_attribute a LEFT JOIN pg_attrdef d ON a.attrelid = d.adrelid AND a.attnum = d.adnum WHERE a.attrelid = '"checkins"'::regclass AND a.attnum > 0 AND NOT a.a...

passing configure options to rake gems:build

On the server (where I am not root), I have compiled libxslt into /home/foo/sw. So I can install my gem like so: gem install nokogiri -- --with-xslt-dir=/home/foo/sw However, this same technique doesn't work with rake: $ rake gems:build -- --with-xslt-dir=/home/foo/sw (in /home/foo/fooapp/releases/20100915071151) If I try to forc...

Rails - Searchlogic to search condition as an array of value

I have two models Employee & Unit. Unit has many Employees. I am using SearchLogic to search employee model. What is the equivalent of below SQL in Searchlogic employees.unit_id IN (1,2,3) I have tried both unit_id_equals_all[] unit_id_equals_any[] But nothing works. Can anyone help? Thanks, Abhilash ...