Hi. I have a model in Rails 3. When creating the record, there are a total of 3 columns for the model.
Right now, Rails allows for creating a record if only 2 of the 3 records are populated?
In rails, how do you tell Rails only create a record if 3 values for each column exist when creating?
thank you
...
Given the following controller:
def create
if @mymodel.save
format.js
else
format.js { render :js => @mymodel.errors }
end
end
What's the Rails way of handling a .JS error response... Do I create .js file with a different file name just for servering Errors?
Do I add an IF ELSE in the .js file?
t...
I am trying to write specs for a working file upload functionality using attachment_fu. However, the sample code given by the author for testing requires me to require action_controller/test_process so that I have access to ActionController::UploadedStringIO class. I have used this before in rails 2.x but for rails 3, it fails to locate ...
Short and simple question:
fork { something_that_takes_a_few_seconds_and_doesnt_concern_the_user }
respond_to ...
Is there any reason not to do this sort of thing in a rails app? In PHP we're currently relying on external queueing systems like beanstalk or Amazon's SQS coupled with an asynchronous task worker that's pulling things o...
I am trying to build in color-coding in my site for a particular class method, such that some values display in a different color if they are low.
I just defined a class method that translates numbers stored in my database to words that are displayed to my users.
# model.rb
def numbers_explained
numbers_explained = case number
wh...
I want Rails 3 to dynamically grab assets depending on current domain:
mysite.com - assets.mysite.com
mysite.ru - assets.mysite.ru
Is it possible out of the box? Or I should implement it manually?
...
I want to write a rspec test that tests if correct layout is used for controller. (Actually I want to test that no layout is used :) ).
I did some googling and also Looked here http://stackoverflow.com/questions/109284/testing-rendering-of-a-given-layout-with-rspec-rails
But all of this does not work for Rails3.
I have used:
controll...
A couple of my model classes are getting a little cluttered with all these "validates" calls, so I thought I'd be able to move them into a separate class and 'require' that, but it doesn't seem to work.
class Auction < ActiveRecord::Base
require 'auction/validations'
...
class Auction::Validations
include ActiveModel::Validations...
I did the:
gem install hpricot --platform=mswin32
It's correctly listed when I do gem list:
*** LOCAL GEMS ***
abstract (1.0.0)
actionmailer (3.0.0)
actionpack (3.0.0)
activemodel (3.0.0)
activerecord (3.0.0)
activeresource (3.0.0)
activesupport (3.0.0)
arel (1.0.1)
builder (2.1.2)
bundler (1.0.0)
columnize (0.3.1)
erubis (2.6.6)
hp...
Hi, I'm using Ryan's solution to add and remove nested model fields dynamically through JavaScript using jQuery.
There are 4 models: client, c_person; project, p_person. And one-to-many associations: client has many c_people and project has many p_people (these are people from client side but they belongs to project). Hope it isn't to...
I have such view:
<h1>Ajax show</h1>
Click this link to show the current
<%= link_to 'time', {:action => 'time', :update => 'time_div'}, :remote => true %>
<div id='time_div'>
</div>
Controller:
class PagesController < ApplicationController
def formula
end
def time
render :text => "The current time is #{Time.now.to_s}"
...
I have a Rails 3 app that defines some classes like normal. I am trying to figure out how to reopen one of those classes within a plugin (generated by "rails generate plugin ..."), and have both of the files (the file in the app itself and the file in the plugin) automatically reload on every request in development mode.
A simple exampl...
Hello,
For a user I have the following as an example:
[#<Permission id: 1, project_id: 3, role_id: 1, user_id: 1>, #<Permission id: 43, project_id: 2, role_id: 1, user_id: 1>, #<Permission id: 44, project_id: 4, role_id: 1, user_id: 1>, #<Permission id: 45, project_id: 5, role_id: 2, user_id: 1>, #<Permission id: 46, project_id: 6, rol...
What's the equivalent of relative_url_root in ActionMailer?
I've tried setting it up in default_url_options, but it appends the parameter in the query string.
Adding :skip_relative_url_root = false doesn't work either.
Using :host = 'somehost.com/subdir' does work, but is that appropriate?
Thanks!
...
I have a complex form (like Ryan B's Complex Form Railscasts) where I have a few levels of database tables being altered at the same time.
The code for this dropdown box works in that it delivers the correct integer to the database. But, despite numerous attempts I cannot get it to correctly reflect the database's CURRENT value. How can...
I am combining div toggling with complex forms: http://railscasts.com/episodes/75-complex-forms-part-3
My specific situation: I have a few nested fields being built in table/new.html.erb and Customer/_customer_note_fields. Ordinarily, I would do something like the following to have toggled divs:
# view
<a class="toggle" rel="toggle[exp...
Hello,
I have the following form_for tag:
<%=form_for [:project, @permission], :remote => true do |f| %>
<form method="post" id="edit_permission_52" data-remote="true" class="edit_permission" action="/projects/52/permissions/useronspace" accept-charset="UTF-8">
The ID looks right = edit_permissions_52
But the action path is all me...
class CreateCrews < ActiveRecord::Migration
def self.up
create_table :crews do |t|
t.string :title
t.text :description
t.boolean :adult
t.boolean :private
t.integer :gender_id
t.boolean :approved, :default => false
t.timestamps
end
end
def self.down
drop_table :crews
end
end
...
Model has accepts_nested_attributes_for for the relation and the form is as follows:
= semantic_form_for @obj, :url => path do |f|
= f.inputs do
= f.input :name
= f.semantic_fields_for :photos do |p|
= p.inputs :desc
= f.buttons
The form works well and everything is fine. However, I would like to display each phot...
I'll use the generic blog example.
class Post < ActiveRecord::Base
has_many :comments
end
class Comment < ActiveRecord::Base
belongs_to :post
end
When querying Post, how do you access its associations (i.e. :comments)?
This should be the easiest thing in the world, but I haven't found any documentation on it. Even http://edgeguid...