There seems to be several technology demos such as http://rails-primer.appspot.com/ on how to run Rails on App Engine. What would be the easiest way to run Rails on App Engine?
Hello,
I have the following hash of countries;
COUNTRIES = {
'Albania' => 'AL',
'Austria' => 'AT',
'Belgium' => 'BE',
'Bulgaria' => 'BG',
.....
}
Now when I output the hash the values are not ordered alphabetically AL, AT, BE, BG ....but rather in a nonsense order (at least for me)
How can I output the hash having the values ordered alphabetically?
I have an app that allows a user to create new projects, and the search for them later. One of the options they have when creating a project is giving them start and end dates. At the moment all the code works properly for creating and searching on the dates, but I am now wanting to restrict what dates the user can enter.
I am needing for an error to flag up when the user tries to enter an end date that is before the start date. It's really more for when the user is creating the project. Here is my code so far =
Application.js
//= require jquery
//= require jquery_ujs
//= require jquery-ui
//= require jquery.ui.all
//= require_tree .
$(function() {
$("#project_start_date").datepicker({dateFormat: 'dd-mm-yy'});
});
$(function() {
$("#project_end_date").datepicker({dateFormat: 'dd-mm-yy'});
});
jQuery(function(){
jQuery('#start_date_A').datepicker({dateFormat: "dd-mm-yy"});
});
jQuery(function(){
jQuery('#start_date_B').datepicker({dateFormat: "dd-mm-yy"});
});
New View:
<div class="start_date" STYLE="text-align: left;">
<b>Start Date:</b>
<%= f.text_field :start_date, :class => 'datepicker', :style => 'width: 80px;' %>
</div>
<div class="end_date" STYLE="text-align: left;">
<b>End Date:</b>
<%= f.text_field :end_date, :class => 'datepicker', :style => 'width: 80px;' %>
</div>
Search View:
Start dates between
<%= text_field_tag :start_date_A, params[:start_date_A], :style => 'width: 80px;' %>
-
<%= text_field_tag :start_date_B, params[:start_date_B], :style => 'width: 80px;' %></br>
I tried following examples online to get this to work by doing this in the application.js file:
$(function() {
$("#project_start_date,#project_end_date").datepicker({dateFormat: 'dd-mm-yy'});
});
jQuery(function(){
jQuery('#start_date_A,#start_date_B').datepicker({dateFormat: "dd-mm-yy"});
});
But then the script doesn't run. I am new to rails and javascript so any help at all is appreciated. Thanks in advance.
UPDATE:
Don't know why my question has been voted to be closed. It's quite simple:
I need an error to flag up when the user tries to enter an end date that is before the start date. How can I do that??
I have an entries controller that allows users to add contact information the website. The user-submitted information isn't visible to users until the administrator checks a check box and submits the form. So basically my problem is that if I check the check box as an administrator while initially creating an entry (entries#new) the entry will be publicly visible as expected, but if a non-admin user creates an entry (the normal user view doesn't include the 'live' check box, only the admin one does) then that entry is stuck in limbo because the entries#edit view for some reason doesn't update the boolean check box value when logged in as an admin.
entries#new view:
<% form_for(@entry) do |f| %>
<%= f.error_messages %>
Name<br />
<%= f.text_field :name %>
Mailing Address<br />
<%= f.text_field :address %>
#...
<%- if current_user -%>
<%= f.label :live %><br />
<%= f.check_box :live %>
<%- end -%>
<%= f.submit 'Create' %>
<% end %>
entries#edit (only accessible by admin) view:
<% form_for(@entry) do |f| %>
<%= f.error_messages %>
<%= f.label :name %><br />
<%= f.text_field :name %>
Mailing Address<br />
<%= f.text_field :address %>
<%= f.label :live %><br />
<%= f.check_box :live %>
<%= f.submit 'Update' %>
<% end %>
Any ideas as to why an administrator can't update the :live check box from the edit view?
I would greatly appreciate any suggestions. I'm new to rails. I can post more code if it's needed. Thanks for reading my question.
I can't for the life of me figure this out, even though it should be very simple.
How can I replace all occurrences of "(" and ")" on a string with "\(" and "\)"?
Nothing seems to work:
"foo ( bar ) foo".gsub("(", "\(") # => "foo ( bar ) foo"
"foo ( bar ) foo".gsub("(", "\\(") # => "foo \\( bar ) foo"
Any idea?
I always run autospec to run features and RSpec at the same time, but running all the features is often time-consuming on my local computer. I would run every feature before committing code.
I would like to pass the argument in autospec command. autospec doesn't obviously doesn't accept the arguments directly. Here's the output of autospec -h:
autotest [options]
options:
-h
-help You're looking at it.
-v Be verbose.
Prints files that autotest doesn't know how to map to
tests.
-q Be more quiet.
-f Fast start.
Doesn't initially run tests at start.
I do have a cucumber.yml in config directory. I also have rerun.txt in the Rails root directory. cucumber -h gives me a lot of information about arguments.
How can I run autospec against features that are tagged as @wip? I think I can make use of config/cucumber.yml. There are profile definitions. I can run cucumber -p wip to run only @wip-tagged features, but I'd like to do this with autospec.
I would appreciate any tips for working with many spec and feature files.
I would like to do is to know if a user has been created in the system in the last 10 second.
so i would do:
def new_user
if(DateTime.now - User.created_at < 10)
return true
else
return false
end
end
IT is just an idea , how can i do it correctly?
thank you
I'm using cURL to test a RESTFul HTTP web service. The problem is I'm normally submitting a bunch of values normally like this:
curl -d "firstname=bob&lastname=smith&age=25&from=kansas&someothermodelattr=val" -H "Content-Type: application/x-www-form-urlencoded" http://mysite/people.xml -i
The problem with this is my controller will then have code like this:
unless params[:firstname].nil?
end
unless params[:lastname].nil?
end
// FINALLY
@person = People.new(params[:firstname], params[:lastname], params[:age], params[:from])
etc..
What's the best way to simplify this? My Person model has all the validations it needs. Is there a way (assuming the request has multi-model parameters) that I can just do:
@person = People.new(params[:person])
and then the initializer can take care of the rest?
I would like to create a virtual attribute that will always be included when you do model_instance.inspect. I understand that attr_reader will give me the same thing as just defining an instance method, but I would like this attribute to be part of the object's "make up"
How can I accomplish this?
Thanks!
Does anyone knows how to force WEBrick to process more than one request at a time? I'm using some Ajax on my page for long running database-related tasks and I can clearly see the requests are being processed in a pipeline.
The authlogic rails gem is doing a LOWER in the sql query.
SELECT * FROM `users` WHERE (LOWER(`users`.email) = '[email protected]') LIMIT 1
I want to get rid of the LOWER part since it seems to be slowing down the query by quite a bit.
I'd prefer to just lower the case in the code since this query seems to be expensive.
I'm not sure where to change this behavior in authlogic.
Thanks!
I may be missing something but I am stuck in this scenario:
I have a non activerecord model, which I want to test. I have derived its test case class from: Test::Unit::TestCase.
However, the test case class for the model, uses within itself, other activerecord model classes and I want to load fixtures for them. My problem is that the fixtures class method is available only when I subclass the test case class from ActiveSupport::TestCase (it is defined within ActiveRecord::TestFixtures which gets included in ActiveSupport::TestCase).
Any help, coz running the tests gives me the error: undefined method "fixtures" (which is understandable) and in case I derive my test case class from ActiveSupport::TestCase it complains that there is no corresponding DB table. Also, I don't want to create a dummy table for backing my model class.
Thanks a ton!
I have a singleton in my FTP app designed to store all of the types of servers that the app can handle, such as FTP or Amazon S3. These types are plugins which are located in the app bundle. Their path is located by applicationWillFinishLoading: and sent to the addServerType: method inside the singleton to be loaded and stored in an NSMutableDictionary.
My question is this:
How do I bind an NSDictionaryController to the dictionary inside the singleton instance? Can it be done in IB, or do I have to do it in code? I need to be able to display the dictionary's keys in an NSPopupButton so the user can select a server type.
Thanks in advance!
SphereCat1
I currently have a users model and controller, whenever a user is created it makes there profile url at example.com/users/userid. I also have a users/new page and a users/index page. The issue is that when I try to create a users/selected users page rails thinks its a user id and gives me this error. "Couldn't find User with id=selectedusers." I've previously been able to fix this by directly calling the pages in the controller e.g index, or new but I'm not sure how to handle a page that doesent have a function in the controller. Thank you
So I have made a stripe payment option in my app. When I click the button pay now, it shows me that the payment is successful. and when I go to my stripe account and go to stripe-test and check logs, I can see my test payment with the code 200 OK. But this payment doesn't show in stripe-test events, or in stripe-test payments. Are the payments from logs processed the next day or am I doing something wrong?
def charge
Stripe.api_key = "some_test_api_key"
customer = Stripe::Customer.retrieve(stripe_customer_id)
if stripe_customer_id.nil?
Stripe::Charge.create(
:amount => 2500,
:currency => "cad",
:customer => stripe_customer_id,
:description => "Usage charges for #{name}"
)
end
rescue Stripe::StripeError => e
logger.error "Stripe Error: " + e.message
errors.add :base, "Unable to process charge. #{e.message}."
false
end
I am trying to compile a library originally written for Cocoa. Things are good until it looks for the function marg_setValue(). It says it can't find it.
I have googled and found it is defined in How can I use this file in cocoa-touch? Or does cocoa-touch not support runtime.
I have a collection with an index on :created_at (which in this particular case should be a date)
From rails what is the proper way to save an entry and then retrieve it by the date?
I'm trying something like:
Model:
field :created_at, :type = Time
script:
Col.create(:created_at = Time.parse(another_model.created_at).to_s
and
Col.find(:all, :conditions = { :created_at = Time.parse(same thing) })
and it's not returning anything
Yes, I've read and done teh Google many times but I still can't get this working... maybe I'm an idiot :)
I have a system using tickets. Start date is "created_at" in the timestamps. Each ticket closes 7 days after "created_at". In the model, I'm using:
def closes
(self.created_at + 7.days)
end
I'm trying to create another method that will take "closes" and return it as how many days, hours, minutes, and seconds are left before the ticket closes. Anyone want to help and/or admonish my skills? ;)
My model class is:
class Category < ActiveRecord::Base
acts_as_nested_set
has_many :children, :foreign_key => "parent_id", :class_name => 'Category'
belongs_to :parent, :foreign_key => "parent_id", :class_name => 'Category'
end
def to_param
slug
end
Is it possible to have such recursive route like this:
/root_category_slug/child_category_slug/child_of_a_child_category_slug ... and so one
Thank you for any help :)
I just got started with rails, and when I testing in development mode, I see in the logs that my Mailer action is taking 1175ms. Is there anyway to find out what exactly is the slow step?
Also, there is a line that says (View:2, DB:1). I assume the DB means number of database lookups, but what about the view?
I have an object which whether validation happens or not should depend on a boolean, or in another way, validation is optional. I haven't found a clean way to do it. What I'm currently doing is this (disclaimer: you cannot unsee, leave this page if you are too sensitive):
def valid?
if perform_validation
super
else
super # Call valid? so that callbacks get called and things like encrypting passwords and generating salt in before_validation actually happen
errors.clear # but then clear the errors
true # and claim ourselves to be valid. This is super hacky!
end
end
Any better ways?
Before you point to the :if argument of many validations, this is for a user model which is using authlogic so it has a lot of validation rules. You can stop reading here if you belive me.
If you don't, authlogic already sets some :ifs like:
:if => :email_changed?
which I have to turn into
:if => Proc.new {|user| user.email_changed? and user.perform_validation}
and in some other cases, since I'm also using authlogic-oid (OpenID) I just don't have control over the :if, authlogic-oid sets it in a way I cannot change it (in time) without further monkey patching. So I have to override seemingly unrelated functions, catch exceptions if a method doesn't exist, etc. The previous hacky solution if the best of my two attempts.
I have the following test in my Rails Application:
it "should validate xml" do
builder = Builder::XmlMarkup.new
builder.server(:name => "myServer", :ip => "192.168.1.1").should == "<server name=\"myServer\" ip=\"192.168.1.1\"/>"
end
The problem is that this test passes sometimes, because the order of the xml tag attributes is unpredictable. Is there a way to force this order? Is there any other easy way to build xml?
This example is simplified, I have a big XML. My problem is that I want to do an integration test, which compares a WebService call with a fixed XML file. Otherwise, I would have to parse the xml and verify element by element in the XML.
Hello, so I have this big method in my application for newsletter distribution. Method is for updating rayons and i need to assigned user to rayon. I have relation n:n through table colporteur_in_rayons witch have attributes since_date and _until_date.
I am junior programmer and i know this code is pretty dummy :)
I appreciated every suggestion.
def update
rayon = Rayon.find(params[:id])
if rayon.update_attributes(params[:rayon])
if params[:user_id] != ""
unless rayon.users.empty?
unless rayon.users.last.id.eql?(params[:user_id])
rayon.colporteur_in_rayons.last.update_attributes(:until_date = Time.now)
Rayon.assign_user(rayon.id,params[:user_id])
flash[:success] = "Rayon #{rayon.name} has been succesuly assigned to #{rayon.actual_user.name}."
return redirect_to rayons_path
end
else
Rayon.assign_user(rayon.id,params[:user_id])
flash[:success] = "Rayon #{rayon.name} has been successfully assigned to #{rayon.actual_user.name}."
return redirect_to rayons_path
end
end
flash[:success] = "Rayon has been successfully updated."
return redirect_to rayons_path
else
flash[:error] = "Rayon has not been updated."
return redirect_to :back
end
end
I'm looking for the best way to write unit test for code that POSTs to an external web service. The body of the POST request is an XML document which describes the actions and data for the web service to perform.
Now, I've wrapped the webservice in its own class (similar to ActiveResource), and I can't see any way to test the exact XML being generated by the class without breaking encapsulation by exposing some of the internal XML generation as public methods on the class. This seems to be a code smell - from the point-of-view of the users of the class, they should not know, nor care, how the class actually implements the web service call, be it with XML, JSON or carrier pigeons.
For an example of the class:
class Resource
def new
#initialize the class
end
def save!
Http.post("http://webservice.com", self.to_xml)
end
private
def to_xml
# returns an XML representation of self
end
end
I want to be able to test the XML generated to ensure it conforms to what the specs for the web service are expecting. So can I best do this, without making to_xml a public method?