Search Results

Search found 9825 results on 393 pages for 'ruby'.

Page 24/393 | < Previous Page | 20 21 22 23 24 25 26 27 28 29 30 31  | Next Page >

  • Sort by values from hash table - Ruby

    - by Adnan
    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?

    Read the article

  • Ruby - Escape Parenthesis

    - by Todd Horrtyz
    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?

    Read the article

  • Ruby library for manipulating existing PDF

    - by simonwh
    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.

    Read the article

  • Ruby on Rails: reducing complexity of parameters in a RESTFul HTTP POST request (multi-model)

    - by randombits
    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?

    Read the article

  • Ruby comparing dates

    - by fenec
    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

    Read the article

  • turn a ruby hash into html list

    - by JAlberto
    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

    Read the article

  • ruby on rails group by with null values problem

    - by winter sun
    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

    Read the article

  • Ruby on Rails check box not updating on form submission

    - by user284194
    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.

    Read the article

  • Passing options in autospec with Cucumber in Ruby on Rails Development

    - by TK
    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.

    Read the article

  • Ruby on rails form variables as array items

    - by Francois
    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"

    Read the article

  • Help with Ruby Date Compare

    - by Kevin
    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? ;)

    Read the article

  • MongoDB ruby dates

    - by MB
    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

    Read the article

  • Ruby does 'elseif' still exist

    - by catchmikey
    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

    Read the article

  • Ruby Rails _without_ ActiveRecord

    - by devlearn
    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,

    Read the article

  • ruby search drop down

    - by cesia
    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?

    Read the article

  • XML testing in Rails - Fixed attributes order in Builder::XmlMarkup in ruby -

    - by Daniel Cukier
    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.

    Read the article

  • Checking multiple conditions in Ruby (within Rails, which may not matter)

    - by Ev
    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?

    Read the article

  • Disable validation in an object in Ruby on Rails

    - by J. Pablo Fernández
    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.

    Read the article

< Previous Page | 20 21 22 23 24 25 26 27 28 29 30 31  | Next Page >