I've added a select box to a form partial, but unsure about how to pull the currently selected value in the database back into the select box.
Here's what I have in my partial:
<%= f.select 'status', options_for_select([['Publish', 1], ['Draft', 2]], 1) %>
I know that the last "1" is currently setting the value when the page is loaded...
I'm running Mac OSX 10.6.4 and have installed RVM. Its been great so far, I really love the way it lets me manage having multiple versions of rails and ruby on the same machine without headaches!
However, I don't want to have to install certain gems (such as passenger) for each setup. Is there a way to share gems between gemsets? I ha...
I tested an association on mysql as follows and it works:
User.campaigns
These are the associations in the Models:
Campaign belongs_to :user
User has_many :campaigns
However, when I run it on heroku which uses Postgres, I get the following:
CampaignsController#index (ActiveRecord::StatementInvalid) "PGError: ERROR: column campaig...
When I try to open my site on IE (development, environment, or online), it crashes every time. This is my server readout upon entering the home page (it actually crashes on any page view after this):
Rendered shared/_footer.erb (0.0ms)
Rendered welcome/index.html.erb within layouts/index (179.0ms)
Completed 200 OK in 204ms (Views: 203.0...
I wanted add a hook on before_save.
Validation happens before "before_save" is called, so I moved it to before_validation :on =>:save.
Now the problem is, when I do @object.save_without_validation (sometimes I had to use this). my before_validation hook doesn't get called.
Am I missing something or is there a more robust way of adding...
Hello,
Heroku doesn't seem to update my database schema when I deploy. Here are the details:
Here is what is should look like for the User class:
create_table "users", :force => true do |t|
t.string "username"
t.datetime "created_at"
t.datetime "updated_at"
t.string "email"
t.string "encrypted_password"
t.string "salt"
t.strin...
HTTP PUT isn't entirely cross browser so Rails (I'm using Rails 3) supports using POST and passing the _method query param. This is great, but it doesn't seem to work when sending JSON.
Example:
$.ajax({
url: window.location.pathname,
type: 'POST',
contentType: 'application/json',
data: JSON.stringify({_method:'PUT', p...
Hi,
Is that possible to establish a relationship between Tree and Branch such as:
class Tree < ActiveRecord::Base
has_many :branches
end
class Branch < ActiveRecord::Base
belongs_to :tree
end
But with an array of foreign keys branch_ids stored in Tree? I know it's the opposite of the default process, but I want to do so (just fo...
I want to create a select tag using rails collection_select or options_for_select with the items of an array which are not model based. The value of the option should be the array index of each item.
Example: desired output for ['first', 'second', 'third']:
<select id="obj_test" name="obj[test]">
<option value="0">first</option>
...
So what I'd like to do is to override the default date_select method (I'd like to make an 'optional / unspecified' date input). What I've tried so far is this:
lib/overrides.rb
ActionView::Helpers::DateHelper::DateTimeSelector.class_eval do
def build_selects_from_types(order)
select = ''
order.reverse.each do |type|
sep...
Hi,
I recogn that I can use an options_from_collection_for_select inside a select box to display a list of options inside it. If I add (first.id), it will select the first option as default preselection. Example :
options_from_collection_for_select(@hauses, 'id', 'timebuild', @hauses.first.id)
However, if in the index.rhtml, I put th...
My Rails application is currently using JSON as the respond_to format for AJAX forms on the site. I'm planning to create a public API for the application, and I'd like to use JSON for it also. How might I distinguish between an AJAX form and an API call in my controllers if the requested format for both is JSON?
...
Hi,
I would like to customize the following flash msg provided by devise
in the devise.en.yml file:
devise:
failure:
unconfirmed: 'You have to confirm your account before continuing.'
with ruby code in order to get a link to new_user_confirmation_path.
Someone give me a solution in stackoverflow but I don't know where I
hav...
I am currently looking for a markup language to use in a project. I want to allow site vistors to edit a wiki like page using a markup language (not HTML).
I am implementing this site in Ruby on Rails, and would prefer (although not bound) to use something that already has strong support in the form of a gem.
There are a few main thing...
ruby on my development machine:ruby 1.8.7 (2010-01-10 patchlevel 249) [i486-linux]
capistrano on my development machine: Capistrano v2.5.5
OS on development machine: ubuntu 10.04 desktop edition
server is Amazon web service instance running on ubuntu server 64 bit 10.04
ruby on server: ruby 1.8.7 (2010-01-10 patchlevel 249) [x86_64-linu...
Hi folks,
I'm trying to add a fields_for attribute to a nested rails form. Any time I try to create a new object, it returns
Message(#58819400) expected, got
Array(#18903800) ...
app/controllers/discussions_controller.rb:53:in
`create'
If I try to access nested fields_for from forms based on non-nested resources (aka "for...
I want to build an application using Rails 3.0.1 but do not want to switch permanently from Rails 2.3.8 and thus require to use Rails 3.0.1 only for that specific application.
Is using bundles an answer, if yes than how??
Thanks in advance.
...
Hello.
I have a nested controller that works fine, and I'd like to setup rspec to also test a nested controlled, but it doesn't test the controller unless I specify it.
i.e. my rspec test controller is here:
/spec/controllers/organizations/memberships_controller.rb
but when I run rspec to test everything, it tests everything except th...
As I remember, on Windows, all the gems get installed relative to c:\ruby192, so can we actually have different paths such as
c:\ruby187_rails238
c:\ruby187_rails301
c:\ruby192_rails301
c:\ruby192_try
and therefore have 2 Ruby installations and 2 gemsets for each of them, and create more gemsets as needed this way. (just make sure to...
I'm really struggling with how to handle Error Handling in Rails 3. I have hacked some ideas that could work but would rather do it the proper way. If anyone can help or give guidance I would appreciate it. Here is what I have so far
ItemController
def show
@item = Item.find(params[:id])
@note = @item.notes.new
respond_w...