ruby-on-rails

LocalJumpError (Ruby)

Hi I'm getting an odd LocalJumpError which only occurs when I'm in staging or production on Ubuntu. When I'm in development environment and passing the same data to the method, I don't get the error. The error is being returned when I attempt to pass data to the following method: def standard_deviation_percentage(population) retu...

Rails | Cucumber | acl9 | AccessDenied

Hi guys, I am ramping up Cucumber, and I am having a issue getting one of my first tests to pass. The exception I am getting is: And I visit the new contract screen Acl9::AccessDenied (Acl9::AccessDenied) /usr/local/lib/ruby/1.8/benchmark.rb:308:in `realtime' (eval):2:in `visit' ./features/step_definitions/manage_contracts_ste...

ROR - My logic works, Boolean value doesn't post

Hello fellas, My logic tests an inventory supply; and the < operator functions fine. How do I assign boolean values to "instock"? (using POST) In this test, under both conditions the value remains unchanged and this sample code does not work. Also this code is placed in an html.erb file, is there a better place for this code? <% if @i...

insert a value into an integer column without updating it, but adding it's contents.

hello i have: ActiveRecord::Base.connection.execute "UPDATE ventas SET costo_de_compra = #{@nuevo_costo} WHERE id = #{@vid};" but this updates that column value every time it's recursed, what i want is just to insert that value to the already stablished values in that column... in proper instance i want to add the values to an intege...

Unfortunately this works: ROR Comparison in Activerecord - update.

Unfortunately this mess works: Do you have suggestings for cleaning up this code: I'm trying to use a activerecord to compare two table columns, "needed" and "amount" then update a boolean column, depending on the returned data. Totally breaking do-not-repeat coding. def update @inventory = Inventory.find(params[:id]) respond_...

Order products by association count

Hello everyone i have Class Product has_many :sales end Class Sale belongs_to :product end How do i get the most sold products.. (Product find all.. order by .. ventas..) ? ...

Doing something before saving a form used with HABTM

Hi I currently have 3 tables. snippet tags snippet_tags I'm using HABTM. So I did a form to save a snippet with tags. Keywords are in a text field, separated by commas. What I need to do is to take the string from this text field, loop on the keywords, check if they exist, if not create them, and THEN save the snippet. I tried with...

order products by association count belongs_to

hi i have Class Sale belongs_to :product, :accessible => true belongs_to :brand, :accessible => true end Class Product has_many :sales belongs_to :brand end Class Brands has_many :products has_many :sales end How do i get the brands that have the most product sales? ...

Keep record of deleted items

Hello i have a rails app that handles sales, right now, what i need is to be able to delete the sale in order to keep accounting clear, but log somewhere else, the details of that record. I am thinking i may need to create a logger, but have no idea how, or maybe another object who gets created on the destroy of the sale. Thanks in adv...

When do I use save!, create! and update_attributes! in Rails?

I'm trying to figure out when to use the bang! versions for saving and updating records? I've read and heard that you don't need them if you're just saving one record or updating a single attribute, if you're confident nothing should go wrong, or to always use them outside of a controller. I guess I'm paranoid about having multiple thing...

Why only ASP.NET have asynchronous programming model?

I works with ASP.NET. IMHO, the asynchronous programming support in ASP.NET is beautiful. That is, we can have BeginXXXX/EndXXXX pair method to improve scalability for resource intensive task. For example, one operation needs to get huge data from database and render it on response web page. If we have this operation synchronous. The t...

ActiveRecord sum errors with postgresql

I am using AR's sum method for a query and seeing this error when using PostgreSQL: PGError: ERROR: function sum(character varying) does not exist LINE 1: SELECT sum("assets".asset_file_size) AS sum_asset_file_size ... HINT: No function matches the given name and argument types. You might need to add explicit type casts. SELECT sum("as...

Trying to install Ruby on Rails on OSX and I get a Gem::RemoteSourceException

What is going on when I get this "HTTP Response 403" error? I am trying to setup Ruby on Rails on OS X 10.5.8 with XCode 3.1.4: Boston:$ ruby --version ruby 1.8.6 (2008-08-11 patchlevel 287) [universal-darwin9.0] Boston:$ gem --version 1.0.1 Boston:$ sudo gem update --system Password: Updating RubyGems... ERROR: While executing gem ...

Building core shop framework in Rails. Suitable or not?

I work at an in-house IT department for company running 10 or so only shops of varying complexity. The shops code has been written over the last 8 years, each shop a new branch growing father and father away from the stem (I guess that makes it a bush?) The need for more and more complex discounts, campaigns and user monitoring are grow...

In Rails, can the options in a select field be edited like a text field?

Hello. I have a problem on my application. I have collection select code <% baskets.each do |f| %> <%= f.select :link, @books.collect{|x| [x.title, x.id]}.unshift(['Please select','']) %> <% end %> How do I make the select option editable like a text field so that I can copy and paste the link to choose from the book collection...

Rails: save a record via belongs_to and setting the foreign key

Is there a better way of writing this code? It just doesn't sit right with me, I feel like there is something really 'rails like' that I should already know: belongs_to :parent_in_use belongs_to :parent_template def after_create new_parent_in_use = ParentInUse.create!(self.parent_template.attributes) self.update_attribute(:parent_i...

How to store word compositions in a relational database in a normalized way?

I'm trying to find a nice way to store word compositions of the following form: exhaustcleaningsystem exhaust cleaning system exhaustcleaning system exhaust cleaningsystem The combinations are given by a default per case. Every word in a composition is stored as a unique row in table 'labels'. labels id value --------------------...

RoR && "coming soon" page.

Hi, I am looking for a simple way to implement simple "coming soon" (pre-launch) page for my project on Ruby on Rails. User should be able to leave an email in order to be notified when project is launched. Is there such a plugin\gem? Or I should do it myself... ...

Ruby on Rails ActiveRecord Validation

I would like to validate attributes in a function like this class User < ActiveRecord::Base validate :check_name( :name ) def check_name( name ) ... if name is invalid ... self.errors.add( :name, 'Name is invalid') end end Can you please write the right code? Please explain the functionality why... THX! ...

Voting Functionality Ruby on Rails - Easy Question

I want to add a "like" functionality to a blog I am creating in Ruby on Rails to let people "thumbs up" a post. Then I would like to be able to display the most liked posts in the side bar. I am new to rails so rely heavily on tutorials and stack overflow. Any good resources or what is this even called. I assumed "voting" for this questi...