I have the following models:
class FieldEntryValue < ActiveRecord::Base
belongs_to :field_entry
end
and
class FieldEntry < ActiveRecord::Base
belongs_to :field
belongs_to :media
has_many :field_entry_values, :dependent => :destroy
accepts_nested_attributes_for :field_entry_values, :allow_destroy => true
end
The FieldEntri...
I have this in my test
Project.should_receive(:find).with(@project).and_return(@project)
but when object receive that method call two times, I have to do
Project.should_receive(:find).with(@project).and_return(@project)
Project.should_receive(:find).with(@project).and_return(@project)
Is there any way how to say something like
Pro...
When Rails loads, does it load all the gems that are installed on the system? I've got 47 gems installed on the server, including all the various Rails gems which have multiple versions. However, both Rails, and all the gems used by the application, are frozen into the application.
Are all those gems getting loaded, and would that cause...
There might be a better way to do this, but I'm trying to make an if statement in rails, based on the current action, in a controller (this will be used in a view).
For example, if its the edit page, or the show page, etc. I'd like a different style for something - is there an if statement that can specify this?
(I need an if statement...
Hi , is there any built in way in rails to convert a model schema into an XML schema , (witch i need to interface with crystal reports)
any help would be great.
Kind regards Jamie
...
Hi, I have a rails app that I'm moving to another server and I figure I should use db:schema:load to create the mysql database because it's recommended. My problem is that I'm using capistrano to deploy and it seems to be defaulting to rake db:migrate instead. Is there a way to change this or is capistrano using db:migrate for a good re...
Hi,
I developed a rails app for a school alumni site.
Now another school wants me to develop a similar site for them.
I want to reuse the app. Data structure will be same but the actual data will be different. Design layout will be similar but design itself will be different.
One option is that I just copy the app and modify it. But i...
What are most common Ruby on Rails antipatterns and how to avoid them?
...
I am new to Ruby on Rails and have been using Scaffolding. On one of the forms I want to be able to have two fields and then have the difference between the two submitted to the database.
Instead of :pickupamount, I want (Ending Amount - Starting Amount) to be calculated and entered into the pickupamount column of my database.
Thanks ...
I need to inspect the bits of an uploaded file before it's ever saved off to the file system. PHP's documentation has a nice page that tells me exactly what properties are available for me to use (http://us3.php.net/manual/en/features.file-upload.post-method.php), but I can't find something similar for Ruby and/or Rails.
I've also tried...
Hi All,
I have 3 model, User, Post, Comment with definition like below
class Post < ActiveRecord::Base
belongs_to :user
has_many :comments
def self.find_other_user_posts
?
end
end
class User < ActiveRecord::Base
has_many :posts
has_many :comments
has_many :posts_commented...
In my application, these "planners" (essentially, article ideas) follow predetermined templates, written in Markdown, with some specific syntax here:
Please write your answer in the following textbox: [...]
Please write your answer in the following textarea:
...So here, on line, you should write one thing.
...Here, on line 2, you shoul...
Alright. While there are a few blog posts here and there purporting to make this process easy, this is absolutely driving me crazy.
Here's what I've done:
I've installed FreeTDS (with and without +mssql) but encounter problems when I use it to connect to my remote DB instance. When I attempt
tsql -H [remote-db-ip] -p 1433 -U [valid-...
Hi, I'm trying to run just one migration out of a whole bunch in my rails app. How can I do this? I don't want to run any of the migrations before or after it. Thanks.
...
As far as I know, .rhtml is deprecated in Rails 2. In some guides there is only .erb, but both RubyMine and NetBeans IDE generate .html.erb and I've also seen it many people using.
I've tested both and they seem to work fine without any errors or warnings, but which one is correct? .erb or .html.erb
...
Say I have a post and category model, with each post belonging to a category. On pretty much every page, I'm getting the list of categories:
@categories = Category.all
This produces an array of Category objects. Now, say that each category has id and name attributes. When viewing a post, I want to display the category name.
I was ...
So I have Authlogic working fine with this user_sessions/new view:
<% form_for @user_session, :url => user_session_path do |f| %>
<% if @user_session.errors.present? %>
Invalid username or password
<% end %>
<%= f.label :login %><br />
<%= f.text_field :login %><br />
<br />
<%= f.label :password %><br />
<%= f.passw...
Rails has a nice idiom that makes it easy for you to have a single action method return properly formated data (json, xml, just the data) based on the format specified by the client (or else deduced from the request. It looks something like this ...
respond_to do |format|
format.html #edit.html.erb
format.json {render :text=> <your...
I ran in to an interesting problem while using the 'tap' method on objects of type 'String'.
"abc".tap { |o| o = "xyz" } # this line returns "abc" instead of "xyz"
The 'tap' method works on objects of other types.
[].tap { |o| o << "xyz" } # this line returns ["xyz"] as expected
I am using Rails 2.3.2 and Ruby 1.8.6 on Windows XP.
...
The ability to have flash messages (notice, error, warning, etc) with embedded links is nice from a user interaction standpoint. However, embedding an anchor tag inside a flash message from the controller is dirty.
Let's assume that a flash message like this is good for usability*:
(borrowed from DailyMile.com)
What tactic would you...