What should know the Entry Level, Mid-level, Senior Developer? Theoretical knowledge, development tools, gems and more. What issues are usually at the interview?
I'm using form_remote_tag(:url => {:controller => "home", :action => "search"}, :update => "mydiv"). When I click submit on the form "mydiv" is populated with the error "Template is missing. Missing template home/search.erb in view path app/views". I've tried multiple render options in def search, but they all result in the same error.
It looks like the search method is trying to use it's default render even though I'm specifying what I want.
I've tried:
render 'index'
render :text => 'Return this from my method!'
Is my url incorrect? Is it not submitting back to my home controller's search method?
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'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 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?
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'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'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
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 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?
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.
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.
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'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
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!
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"
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? ;)
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 an entry.rb model and I'm trying to make a semi-complicated validation. I want it to require one or more of the following fields: phone, phone2, mobile, fax, email or website. How would you write the intended code? Would something like this work?
validates_presence_of :phone and or :phone2 and or :mobile and or :fax and or :email and or :website
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
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