I have no internet connection on server machine, so I need to install gems locally.
I tried
gem install rails-2.3.4.gem
But, I'm getting errors.
How Can I install gems locally.
Thanks.
Has anyone managed to make the example at http://railscasts.com/episodes/196-nested-model-form-part-1 work?
When I followed through the sample, it never saves any question nor the answer to the database but it manages to create a new survey entry.
I am using:
Rails 2.3.5
ruby1.8.6 (2008-08-11 patchlevel 287) [i386-mswin32]
nifty-generators (0.4.0)
Hello everybody
I want to send emails with formatted sender such as "Support team [email protected]".
If delivery method I wrote from "support team <[email protected]>" and from "\"support team\" <[email protected]>" but smtp server says
#: "@" or "." expected after "test"
This means that rails puts full "from" string into braces. How can I fix this without monkeypatching?
I have a ruby array that looks something like this:
my_array = ['mushroom', 'beef', 'fish', 'chicken', 'tofu', 'lamb']
I want to sort the array so that 'chicken' and 'beef' are the first two items, then the remaining items are sorted alphabetically. How would I go about doing this?
G'day guys, I'm currently using fasterCSV to parse a CSV file in ruby, and wondering how to get rid of the initial row of data on a CSV (The initial row contains the time/date information generated by another software package)
I tried using fasterCSV.table and then deleting row(0) then converting it to a CSV document then parsing it
but the row was still present in the document.
Any other ideas?
fTable = FasterCSV.table("sto.csv", :headers => true)
fTable.delete(0)
I have a model (Expense) that contains fields like 'cost'.
I'd like to iterate through all my expenses to find the sum of the cost for all entries belonging to a particular month.
Is there a way to do it in rails directly?
Expense.find(:all, :conditions = .....)
In Rails, I have a question on how to get the multiple params !
for example:
the string in log like this
Processing ConfigurationsController#emergency_config (for 192.168.1.124 at 2010-05-31 11:45:53) [POST]
Parameters: {"authenticity_token"=>"I3GPKyrjmDRLkMIxFVS/47mgEI4ETO/+YW+R8R5Q2GM=", "tid"=>"1", "emergency"=>{"department"=>["1", "2", "3", "4", "5", "6", "7", "8"]}}
so,how can i get the department values from it? who can tell me the answer? thank you!
Are there any examples on the web of how to monitor delayed_job with Monit?
Everything I can find uses God, but I refuse to use God since long running processes in Ruby generally suck. (The most current post in the God mailing list? God Memory Usage Grows Steadily.)
Update: delayed_job now comes with a sample monit config based on this question.
I created a form with scaffold that includes two datetime fields.
I replaced them with a datepicker, and now I'm trying to grab the date from within the controller.
Instead of having ruby do all the magic work with the datefields, I instead just have to fields, start_date and stop_date that I want to use, but I can't figure out how to grab them from within my controller. Hints?
Thanks!
Are there any gems that would help me make a search box like the one for tags on stackoverflow?
(Rails 2.3.5, required IE7 support and graceful no-script fall-back)
P.S.: Do these boxes annoy you or do you think it's a good thing to have one?
When try I following code in a controller, the view renders without using the layout
def xyz
render :partial => 'platinum_home', :layout => 'platinum_layout'
end
But If I do the following inside the partial
<% render(:layout => "platinum_layout") do %>
blah blah blah
<% end %>
It works just fine, is the first example not possible using rails?
Hello everyone,
I'm using the rails-settings gem, and I'm trying to understand how you add functions to ActiveRecord classes (I'm building my own library for card games), and I noticed that this gem uses one of the Meta-programming techniques to add the function to the ActiveRecord::Base class (I'm far from Meta-programming master in ruby, but I'm trying to learn it)
module RailsSettings
class Railtie < Rails::Railtie
initializer 'rails_settings.initialize', :after => :after_initialize do
Railtie.extend_active_record
end
end
class Railtie
def self.extend_active_record
ActiveRecord::Base.class_eval do
def self.has_settings
class_eval do
def settings
RailsSettings::ScopedSettings.for_thing(self)
end
scope :with_settings, :joins => "JOIN settings ON (settings.thing_id = #{self.table_name}.#{self.primary_key} AND
settings.thing_type = '#{self.base_class.name}')",
:select => "DISTINCT #{self.table_name}.*"
scope :with_settings_for, lambda { |var| { :joins => "JOIN settings ON (settings.thing_id = #{self.table_name}.#{self.primary_key} AND
settings.thing_type = '#{self.base_class.name}') AND
settings.var = '#{var}'" } }
scope :without_settings, :joins => "LEFT JOIN settings ON (settings.thing_id = #{self.table_name}.#{self.primary_key} AND
settings.thing_type = '#{self.base_class.name}')",
:conditions => 'settings.id IS NULL'
scope :without_settings_for, lambda { |var| { :joins => "LEFT JOIN settings ON (settings.thing_id = #{self.table_name}.#{self.primary_key} AND
settings.thing_type = '#{self.base_class.name}') AND
settings.var = '#{var}'",
:conditions => 'settings.id IS NULL' } }
end
end
end
end
end
end
What I don't understand is why he uses class_eval on ActiveRecord::Base, wasn't it easier if he just open the ActiveRecord::Base class and define the functions? Specially that there's nothing dynamic in the block (What I mean by dynamic is when you do class_eval or instance_eval on a string containing variables)
something like this:
module ActiveRecord
class Base
def self.has_settings
class_eval do
def settings
RailsSettings::ScopedSettings.for_thing(self)
end
scope :with_settings, :joins => "JOIN settings ON (settings.thing_id = #{self.table_name}.#{self.primary_key} AND
settings.thing_type = '#{self.base_class.name}')",
:select => "DISTINCT #{self.table_name}.*"
scope :with_settings_for, lambda { |var| { :joins => "JOIN settings ON (settings.thing_id = #{self.table_name}.#{self.primary_key} AND
settings.thing_type = '#{self.base_class.name}') AND
settings.var = '#{var}'" } }
scope :without_settings, :joins => "LEFT JOIN settings ON (settings.thing_id = #{self.table_name}.#{self.primary_key} AND
settings.thing_type = '#{self.base_class.name}')",
:conditions => 'settings.id IS NULL'
scope :without_settings_for, lambda { |var| { :joins => "LEFT JOIN settings ON (settings.thing_id = #{self.table_name}.#{self.primary_key} AND
settings.thing_type = '#{self.base_class.name}') AND
settings.var = '#{var}'",
:conditions => 'settings.id IS NULL' } }
end
end
end
end
I understand the second class_eval (before the def settings) is to define functions on the fly on every class that 'has_settings' right ? Same question here, I think he could use "def self.settings" instead of "class_eval.... def settings", no ?
This is somewhat against rails convention but I am trying to have one controller that manages both user session authentication and user registration. I am having troubles figuring out how to go about this.
So far I am merging the User Controller and the Sessions Controller and having the 'new' method deliver both a new usersession and a new user instance.
With the new routes in rails 3 though, I am having trouble figuring out how to generate forms for these items.
Below is the code:
user_controller.rb
class UserController < ApplicationController
def new
@user_session = UserSession.new
@user = User.new
end
def create_user
@user = User.new(params[:user])
if @user.save
flash[:notice] = "Account Successfully Registered"
redirect_back_or_default signup_path
else
render :action => new
end
end
def create_session
@user_session = UserSession.new(params[:user_session])
if @user_session.save
flash[:notice] = "Login successful!"
redirect_back_or_default login_path
else
render :action => new
end
end
end
views/user/new.html.erb
<div id="login_section">
<% form_for @user_session do |f| -%>
<%= f.label :email_address, "Email Address" %>
<%= f.text_field :email %>
<%= f.label :password, "Password" %>
<%= f.text_field :password %>
<%= f.submit "Login", :disable_with => 'Logining...' %>
<% end -%>
</div>
<div id="registration_section">
<% form_for @user do |f| -%>
<%= f.label :email_address, "Email Address" %>
<%= f.text_field :email %>
<%= f.label :password, "Password" %>
<%= f.text_field :password %>
<%= f.label :password_confirmation, "Password Confirmation" %>
<%= f.text_field :password_confirmation %>
<%= f.submit "Register", :disable_with => 'Logining...' %>
<% end -%>
</div>
I imagine I will need to use :url = something for those forms, but I am unsure how to specify.
Within routes.rb I have yet to specify either Usersor UserSessions as resources (not convinced that this is the best way to do it... but I could be).
I would like, however, the registration and login on the same page and have implemented this by doing the following:
routes.rb
match 'signup' => 'user#new'
match 'login' => 'user#new'
What's the best way to go about solving this?
Suppose a service written with RoR starts to use AWS S3 to store some data. What is the best library to use for working with AWS S3? Currently the main two alternatives for me are:
RightScale AWS Ruby gems
http://github.com/rightscale/right_aws
AWS::s3 http://amazon.rubyforge.org/
What are their main advantages and disadvantages? What if later service will need to use other AWS (like EC2)? What other gems do you use and why?
Thanks!
Hi All,
I want to know, what is a rails way of converting a subclass record to another subclass record, just changing type isn't working and also superclass to subclass and vice versa.
Thanks in advance
Markiv
What is your experience using RubyonRailson Heroku in production mode?
Apart of the issue of the expensive https, do you see any drawback in the way it manages processes, memory and storage?
The people at Heroku is quite nice and I'm sure they are willing to answer my questions, but I would like some opinions in the customer side.
Hi!
I have got model Team and I've got (i.e.) team = Team.first :offset => 20. Now I need to get number of position of my team in db table.
I can do it in ruby:
Team.all.index team #=> 20
But I am sure that I can write it on SQL and it will be less expensive for me with big tables.
I'm using Intercom rails in my application and I would like to not include intercom script in a certain situation. So, I would like to skip the intercom after_filter when a value is set in the user session.
I tried that, but it didn't worked:
class ApplicationController < ActionController::Base
before_filter :verify_session
def verify_session
if skip_intercom?
self.class.skip_after_filter :intercom_rails_auto_include
end
end
end
Any idea if it's possible?
In a Rails application I have a Test::Unit functional test that's failing, but the output on the console isn't telling me much.
How can I view the request, the response, the flash, the session, the variables set, and so on?
Is there something like...
rake test specific_test_file --verbose
I have problems to get rspec running properly to test validates_inclusion_of my migration looks like this:
class CreateCategories < ActiveRecord::Migration
def self.up
create_table :categories do |t|
t.string :name
t.integer :parent_id
t.timestamps
end
end
def self.down
drop_table :categories
end
end
my model looks like this:
class Category < ActiveRecord::Base
acts_as_tree
validates_presence_of :name
validates_uniqueness_of :name
validates_inclusion_of :parent_id, :in => Category.all.map(&:id), :unless => Proc.new { |c| c.parent_id.blank? }
end
my factories:
Factory.define :category do |c|
c.name "Category One"
end
Factory.define :category_2, :class => Category do |c|
c.name "Category Two"
end
my model spec looks like this:
require 'spec_helper'
describe Category do
before(:each) do
@valid_attributes = {
:name => "Category"
}
end
it "should create a new instance given valid attributes" do
Category.create!(@valid_attributes)
end
it "should have a name and it shouldn't be empty" do
c = Category.new :name => nil
c.should be_invalid
c.name = ""
c.should be_invalid
end
it "should not create a duplicate names" do
Category.create!(@valid_attributes)
Category.new(@valid_attributes).should be_invalid
end
it "should not save with invalid parent" do
parent = Factory(:category)
child = Category.new @valid_attributes
child.parent_id = parent.id + 100
child.should be_invalid
end
it "should save with valid parent" do
child = Factory.build(:category_2)
child.parent = Factory(:category)
# FIXME: make it pass, it works on cosole, but I don't know why the test is failing
child.should be_valid
end
end
I get the following error:
'Category should save with valid
parent' FAILED Expected #<Category id:
nil, name: "Category Two", parent_id:
5, created_at: nil, updated_at: nil
to be valid, but it was not Errors:
Parent is missing
On console everything seems to be fine and work as expected:
c1 = Category.new :name => "Parent Category"
c1.valid? #=> true
c1.save #=> true
c1.id #=> 1
c2 = Category.new :name => "Child Category"
c2.valid? #=> true
c2.parent_id = 100
c2.valid? #=> false
c2.parent_id = 1
c2.valid? #=> true
I'm running rails 2.3.5, rspec 1.3.0 and rspec-rails 1.3.2
Anybody, any idea?
I want to validate login name with special characters !@#S%^*()+_-?/<:"';. space using regular expression in rubyonrails. These special characters should not be acceptable. What is the code for that?
Thanks,
Pallavi
Need a simple a way of rounding off an Image. I need the corners to be transparent. This link shows how to do it via command line:
http://www.imagemagick.org/Usage/thumbnails/#rounded
What I need is the corresponding RMagick\Ruby code... Thanks!
I am trying to setup my dev environment on my Mac (running Mac OS X 10.6) for my work's rails application. It requires FreeImage and now that I have installed that, I run rake db:migrate and receive the following error:
dyld: lazy symbol binding failed: Symbol not found: _FreeImage_SetOutputMessage
Referenced from: /Users/username/.ruby_inline/Inline_ImageScience_cdab.bundle
Expected in: flat namespace
dyld: Symbol not found: _FreeImage_SetOutputMessage
Referenced from: /Users/username/.ruby_inline/Inline_ImageScience_cdab.bundle
Expected in: flat namespace
Trace/BPT trap
I have tried searching around for the error but am at a complete loss as to where to go or what to try in order to resolve this issue.
I know this seems silly, but I would like to call some of Rails' Text Helpers in a rake task I am setting up. (Thinks like the pluralize and cycle method: http://api.rubyonrails.org/classes/ActionView/Helpers/TextHelper.html)
How would you go about making these available in a rake task, or is it not easily possible?