What should know the Entry Level, Mid-level, Senior Developer? Theoretical knowledge, development tools, gems and more. What issues are usually at the interview?
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 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'm searching for a library to edit already existing PDF's and add a watermark to each page, for example. Could also be blank every other page etc.
There seem to be a few PDF libraries out there, but only very few of them can edit existing PDF's and I'm a bit lost on which way to go.
Any recommendations?
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 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 trying to parse a yaml file like this:
a:
a1:
a2:
b:
b1:
b11:
b2:
i get a hash like this:
{"a"=>{"a1"=>nil, "a2"=>nil}, "b"=>{"b1"=>{"b11"=>nil}, "b2"=>nil}}
and i want to turn it to a list:
%ul
%li a
%ul
%li a1
%li a2
%li b
%ul
%li b1
%ul
%li b11
%li b2
I'm trying to search the most efficent way doesn't matter how deep is the hash
I have an hour table in witch I store user time tracking information,
the table consists from the following cells
project_id
task_id (optional can be null)
worker_id
reported_date
working_hours
each worker enters sevral records per day so generally the table is looking like this
id project_id worker_id task_id reported_date working hours;
== =========== ========= ========= ============= ==============
1 1 1 1 10/10/2011 4
2 1 1 1 10/10/2011 14
3 1 1 10/10/2011 4
4 1 1 10/10/2011 14
the task_id is not a must field so there can be times when the user is not selecting it
and ther task_id cell is empty
now i need to display the data by using group by clouse
so the resualt will be somthing like this
project_id worker_id task_id working hours
========== ========= ========= ==============
1 1 1 18
1 1 18
I did the folowing group by condition
@group_hours=Hour.group('project_id,worker_id,task_id)').select('project_id, task_id ,worker_id,sum(working_hours)as working_hours_sum')
My view looks like this
<% @group_hours.each do |b| %
<%= b.project.name if b.project %
<%= b.worker.First_name if b.worker %
<%= b.task.name if b.task %
<%= b.working_hours_sum %
<%end%
This it is working but only if the task_id is not null when task id is null it present all the records without grouping them like this
project_id worker_id task_id working hours
=========== ========= ========= ==============
1 1 1 18
1 1 4
1 1 14
I will appreciate any kind of solution to this problem
Hey,
where would I place additions to stdlib classes in a rails project? Let's say something like:
class Date
def foo
'foo'
end
end
I thought about the initializer folder but it somehow felt wrong. Ideas?
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 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.
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?
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 have a simple form with text input and text area, but when I submit it the variables seems to be array items instead of just string values?
the form
<%= form_tag(home_kontak_path, :remote => true) do %>
<label>Jou epos adres</label>
<%= text_field(:epos, "", :placeholder => "Jou epos adres", :id => "epos", :class => "input-block-level") %>
<label>Boodskap hier</label>
<%= text_area(:boodskap, "", :rows => "5", :placeholder => "Boodskap hier...", :id => "boodskap", :class => "input-block-level") %>
<%= submit_tag "submit" %>
<% end %>
console output
Started POST "/home/kontak" for 127.0.0.1 at 2012-11-23 11:53:03 +0200
Processing by HomeController#kontak as JS
Parameters: {"utf8"=>"?", "authenticity_token"=>"i+5UWaQeBu7LYGPFBNAbum+67VzyyC82JN2wMlLc/UU=", "epos"=>["text box value"], "boodskap"=>["text area value"], "commit"=>""}
what i would like it to be
instead of
"epos"=["text box value"]
i want it to return
"epos"="text box value"
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? ;)
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
I'm just learning ROR and I came across the if / else statements. I also came across 'elseif' but my text editor (textmate) doesn't pick it up as a keyword, not does the program run properly.
if name == 'Chris'
puts 'What a lovely name.'
elseif name == 'Katy'
puts 'What a lovely name!'
end
I'm using the book, Learn to Program, which was written several years ago. I was wondering if the 'elseif' was changed because when I simply use 'else' it seems to function properly
Hello, I'm looking for any pointers on how to write a rails web app without ActiveRecord.
A doc or an example of a (not too complex) web app using storage backends other than a relational database would be greatly appreciated.
It's not clear on what should be implemented in the model classes in order to make the rails app work without the ActiveRecord layer.
Thanks,
I have a drop down list of Type in my Products model.
I want to be able to search in the Products index.html.erb so a user selects a type from a drop down list, clicks search and all the products matching that type are returned.
I can get normal search methods working where the user enters in their search in a text box but I cannot get it working when they just select from a dropdown. Can anyone help?
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 rubyists and railers,
I have a method which checks over a params hash to make sure that it contains certain keys, and to make sure that certain values are set within a certain range. This is for an action that responds to a POST query by an iPhone app.
Anyway, this method is checking for about 10 different conditions - any of which will result in an HTTP error being returned (I'm still considering this, but possibly a 400: bad request error).
My current syntax is basically this (paraphrased):
def invalid_submission_params?(params)
[check one] or
[check two] or
[check three] or
[check four] etc etc
end
Where each of the check statements returns true if that particular parameter check results in an invalid parameter set. I call it as a before filter with params[:submission] as the argument.
This seems a little ugly (all the strung together or statements). Is there a better way? I have tried using case but can't see a way to make it more elegant.
Or, perhaps, is there a rails method that lets me check the incoming params hash for certain conditions before handing control off to my action method?
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.