A model named 'book' with attributes 'name' and 'id' is given. How can i use this collection select to call the show-action of a certain book? The one code mentioned below returns the following error message:
Couldn't find Book with ID=book_id
<% form_tag(book_path(:book_id)), :method => :get do %>
<p>
<%= label(:book, :id, 'Show ...
I have a little example Rails app called tickets, which views and edits fictional tickets sold to various customers. In tickets_controller.rb, inside def index, I have this standard line, generated by scaffolding:
@tickets = Ticket.find(:all)
To sort the tickets by name, I have found two possible approaches. You can do it this way:
@...
Is there anything explicitly wrong with using has_and_belongs_to_many associations in rails instead of has_many :through? I'm aware of these articles describing differences and work arounds, but they are from 2006. From things I've read on SO, it seems like people think that habtm is old and clunky, but what if a simple many to many jo...
I have configured Apache to look for the presence of a maintenance page and redirect to that page if it is present:
RewriteCond %{DOCUMENT_ROOT}/system/maintenance.html -f
RewriteCond %{SCRIPT_FILENAME} !maintenance.
RewriteRule ^.*$ /system/maintenance.html [L]
This is fairly standard practice for deploying Ruby on Rails apps.
What ...
I have a Product model which validates multiple attributes (including a Paperclip image attachment) like so:
validates_presence_of :name
validates_format_of :name, :with => /^([a-zA-Z0-9\ \-]{3,128})$/i
...
has_attached_file :image
validates_attachment_presence :image
validates_attachment_content_type :image, :content_type => ["image/j...
Assume a query of the following form
operatingExpenses = Expense.find(:all,
{:select=>"categories.activityType, categories.name heading, sum(amount) totalAmount",
:joins => "inner join expense_categories categories on category_id = categories.id ",
:group => "categories.activityType, categories.name",
:order => "...
What's the best way to delete duplicate records in a mysql database using rails or mysql queries?
...
Hi All,
I have the restful_authentication plugin installed in a rails app, with a sessions_controller that has a destroy method like this:
def destroy
self.current_user.forget_me if logged_in?
cookies.delete :auth_token
reset_session
flash[:notice] = "You have been logged out."
redirect_back_or_default('/')
end
In the appli...
I have two rails apps running off the same database, one which runs the client and one which provides an admin interface.
Both the apps have the exact same models defined save for small number of differences. Its tiresome for me to duplicate the vast majority of changes in the models on to both apps.
One way for two apps to use the sam...
Hello, my question involves the following partial view with a remote form:
<% remote_form_for :phone_number, :url => {:controller => "edit", :action => "add_phone_number" }, :update => "phone_number_div" do |form| %>
<%= form.text_field :number%>
<%= form.select :type, PhoneNumber::PHONE_TYPE%>
<%= submit_tag "Add" %>
<% end %>
...
I'm beginning to learn Ruby on Rails, and looking at other peoples code. Is there any way to take an exisiting codebase and create object relationship diagrams or Entity relationship diagrams (ERD's) ?
I know Visio can do some things given a database, but I was hoping to produce diagrams of classes, objects and objects.
...
Hello! I have a Rails application with a daemon that checks a mailbox for any new emails. I am using the Fetcher plugin for this task. The daemon file looks like this:
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../config/environment.rb'
class MailFetcherDaemon < Daemon::Base
@config = YAML.load_file("#{RAILS_ROOT}/config...
I am trying make a complex form (like the railscast) with repeated-auto-complete (modified by Pat Shaughnessy) work for creating articles with many authors (has-many :through). I've got it working as long as I willing to always create new authors when I save an article. How can I get my associated author records to only be created wh...
Is there a way to cache per-request data in Rails? For a given Rails/mongrel request I have the result of a semi-expensive operation that I'd like to access several times later in that request. Is there a hash where I can store and access such data?
It needs to be fairly global and accessible from views, controllers, and libs, like Ra...
I'm developing a website with Ruby on Rails and I have a div with some content. After clicking a link I want that content to get replaced with some other stuff. This works fine with replace_html and rjs.
However, I'd prefer there to be a slight fade/appear (crossfade?) transition between the old and new content. Also the div will be ...
I have the tag functionality working ok but can't generate a tag_cloud
in my controller:
def tag_cloud
@tags = Article.tag_counts # returns all the tags used
in the view:
<% tag_cloud Article.tag_counts.sort { |x, y| x.name <=> y.name }, %w(x-small small normal large x-large) do |tag, css_class| %>
<%= link_to tag.name, tag_url( :t...
I have been following an RSpec tutorial on one of my machines, in the hope of learning more about BDD and TDD. My setup was with Rails 2.2.2 and Rspec 1.1.12
Tonight I decided to continue on my primary machine and moved my code from my portable to my desktop. Not having RSpec, i installed the gem . . .
sudo gem install rspec
sudo gem ...
I need a place to keep last request time for user and don't want to use database for that
...
I'm working on a Flex/Rails app. I've got a model with a has_many :through association that I'm trying to create. I've got it working with checkboxes on the plain rails pages, with the help of blogs like Paul Barry's has-many-through-checkboxes. Now I'm trying to get Flex to do the same and am having difficulty on how to send the equival...
Using the code generated by restful_authentication, we usually get 'localhost' as the URL in the sign up and activation mails. I am trying to create something like this instead:
def signup_notification(user, host)
setup_email(user)
@subject += 'Please activate your new account'
@body[:url] = "http://#{host}/activate/#{user.ac...