Browse the Ruby on Rails Community.

You are here: Forums Recent Posts

Recent Posts

2,003 post(s) found

Pages: 1 2 3 4 5 6 7 8 9 10 11 ... 81

Mikegunderloyheadshot

Authority 50
Posting Rating 90
Sign in to rate this post

Topic: Ask a Rails expert / Couldn't find Product without an ID

Ah, I thought that code looked familiar. Just couldn’t quite put my finger on it.

 
Profile

Authority 0
Posting Rating 0
Sign in to rate this post

Topic: Ask a Rails expert / Couldn't find Product without an ID

@Mike, Thanks a lot. It worked. BTW I’m using attachment_fu
Anyways, You made my day.

 
Mikegunderloyheadshot

Authority 50
Posting Rating 90
Sign in to rate this post

Topic: Ask a Rails expert / Couldn't find Product without an ID

It appears that the problem is likely that your image code is trying to create the image, with a foreign key link back to the product, before the product has been saved (and thus before the product has a primary key).

You might be able to fix this up by adding self.save! at the top of the uploaded_data= method in the Imageable module. I’m not going to take the time to try to set up a working project to test this.

However – I would recommend that you NOT roll your own image handling. This is a solved problem, that you can more easily handle just by using one of several image management plugins out there. My own current preference is Paperclip .

 
Robin

Authority 12
Posting Rating 14
Sign in to rate this post

Topic: Ask a Rails expert / auto complete in rails 2.0

I think, this article can help you http://trix.pl/blog/auto-complete-for-rails-2-0-tutorial.html

 
Profile

Authority 0
Posting Rating 0
Sign in to rate this post

Topic: Ask a Rails expert / Couldn't find Product without an ID

Hi, I’m getting an error while creating new Product with an Image.
Following is the view to create new product:

<h1>New product</h1>
<%= error_messages_for :product %>
<% form_for(@product, :html => {:multipart => true}) do |f| %>
<%= render :partial => 'form', :locals => { :f => f } %>
  <p>
    <%= f.submit "Create" %>
  </p>
<% end %>
#Form Partial
  <p>
    <b>Name</b><br />
    <%= f.text_field :name %>
  </p>

<p>
    <%= f.label :product_set %><br />
    <%= select('product', 'product_set_id', [['choose one', '']] + @product_sets.collect {|pset| [pset.name, pset.id]}) %>    
</p>  
<p>
    <b>Default Quantity</b><br />
    <%= f.text_field :default_qty %>
  </p>
  <p>
    <%= f.label :product_image %><br />
    <%= f.file_field :uploaded_data %>
  </p>

When I try to create a new Product, the error shown is:
    ActiveRecord::RecordNotFound in Admin/product setsController#create
    Couldn't find ProductSet without an ID

and the params passed:
Parameters:

{"product_set"=>{"name"=>"sf",
 "uploaded_data"=>#<ActionController::UploadedStringIO:0x5b39e6c>,
 "category_id"=>"2"},
 "commit"=>"Create",
 "authenticity_token"=>"eaf6fce501dc142e9b2e6da40795a5b74117db57"}

But when I create the same product without selecting any product image file, the new Product gets created successfully.
And the tricky part is when I edit that same product and choose a product image file, the file gets uploaded and the record is put into images model as well, just as the way it should be.
I think there is something with Image model while creating new Product since the product gets created if the Product Image file is left blank.
Since I’m newbie in this Rails world, can you plz figure out whats wrong in my code??
Following are the snippets of project:

#Product Model
class Product < ActiveRecord::Base
    include Imageable

    belongs_to :product_set
    has_many :line_items

    validates_presence_of :name
    validates_numericality_of :price
    validates_uniqueness_of :name
end

#Module: lib/imageable.rb
module Imageable
    def self.included(base)
        base.class_eval do
            has_one :image, :dependent => :destroy, :as => :record
        end
    end

    def uploaded_data=(data)
        unless data.blank?
            image.destroy if image
            self.reload
            create_image :uploaded_data => data
        end
    end
end

#Image Model
class Image < ActiveRecord::Base
    belongs_to :record, :polymorphic => true
    has_attachment :content_type => :image, 
            :storage => :file_system, 
            :max_size => 500.kilobytes, 
            :processor => 'ImageScience', 
            :path_prefix => 'public/records'

    validates_as_attachment
end

#ProductController create method
    def create
    @product = Product.new(params[:product])

    respond_to do |format|
      if @product.save
        flash[:notice] = 'Product was successfully created.'
        format.html { redirect_to(@product) }
        format.xml  { render :xml => @product, :status => :created, :location => @product }
      else
        format.html { render :action => "new" }
        format.xml  { render :xml => @product.errors, :status => :unprocessable_entity }
      end
    end
  end

 #Image Migration
 class CreateImages < ActiveRecord::Migration
  def self.up
    create_table :images do |t|
      t.integer :record_id
      t.string :record_type
      t.string :filename
      t.string :content_type
      t.integer :size
      t.integer :height
      t.integer :width

      t.timestamps
    end
  end

  def self.down
    drop_table :images
  end
end

Browser Error:
 ActiveRecord::RecordNotFound in ProductsController#create

Couldn't find Product without an ID

RAILS_ROOT: D:/InstantRails-2.0-win/rails_apps/wedding
Application Trace | Framework Trace | Full Trace

D:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/base.rb:1360:in `find_from_ids'
D:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/base.rb:537:in `find'
D:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/base.rb:2329:in `reload_without_dirty'
D:/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/dirty.rb:90:in `reload'
lib/imageable.rb:11:in `uploaded_data='
app/controllers/products_controller.rb:45:in `new'
app/controllers/products_controller.rb:45:in `create'
...
...
Request

Parameters:

{"commit"=>"Create",
 "product"=>{"name"=>"Product2",
 "uploaded_data"=>#<ActionController::UploadedStringIO:0x5a8ee18>,
 "default_qty"=>"35",
 "product_set_id"=>"4"},
 "authenticity_token"=>"eaf6fce501dc142e9b2e6da40795a5b74117db57"}

 
Profile

Authority 37
Posting Rating 0
Sign in to rate this post

Topic: Rails in the workplace / Issues in Migration to Ruby On Rails

Its growing in india. Guys, I am working in Rails since from July 2007. When i started working, i had hardly found any company/guys. But now after a year, on my interaction with TL’s and PM’s it getting pushed to good level. Only problem is do we have guys on ROR. “50:50”. India is a service oriented hub and they do swim only when they have fish and boats. So it takes couple of months to have resources, so that companies can adopt .But i feel its getting or already started..

Even in new Organisation wherein i am currently associate , have asked me to started groups to get guys from different domains to Rails. Wise people!.
And in one very good company, TL’’s are doing Rails mini projects to start Rails work.

Cheers!.
Imran

 
Robin

Authority 12
Posting Rating 14
Sign in to rate this post

Topic: Ask a Rails expert / Paypal(How to set u/p)

When I implemented PayPal to rails application, I used article wrote by Cody Fauser. It was wery helpfully for me. Try to read maybe it will be helpfully for you too.
There is the link http://www.codyfauser.com/2008/1/17/paypal-express-payments-with-activemerchant
After implementing, you must visit the paypal development site. https://developer.paypal.com/
There make your account. They give you your “api_login”, “api_password” and “api_signature”. This use for your paypal testing.

I hope it help you

 
Profile

Authority 50
Posting Rating 40
Sign in to rate this post

Topic: Ask a Rails expert / HTML to XML ---> get title & description

Use hpricot and find them with an xpath. ”//html/head/title” for the title, etc.

 
Wwr-jess

Authority 12
Posting Rating 0
Sign in to rate this post

Topic: Ask a Rails expert / Accessing controller actions from scripted page?

Hello, I am not sure how to markup the code, so I am using external pasties. (Your help or direction to the markup howto page is welcome.)

1) I wrote a script that compiles/produces thousands of pages via output <<eof blocks>
2) I now need to incorporate charts and graphs, that are not accessible through #{graph} notation in the scripted page
3) I wrote a data model to compile a bunch of stock charts for the pages, and will commence this work, unless there is a more efficient way to reach the controller through a scripted page.
4) The application.haml looks like:

if static_page
= yield
else
= Standard App Template
= yield
end

here are the pasties:

portion of scripted output: http://pastie.org/265913
controller action I wish to reach: http://pastie.org/265915

Again, plese let me know if plain html works here.

 
Atcaaac4eecompfcnizgu-dgz65i9p1tjty1hxko6wfsozkt835glzltxsfkxxnkkz7wafgyqhdw4woyfgaw-_xlmxosajtu9vbc4qhz46tprxtfdvbjmese-bfomq

Authority 37
Posting Rating 79
Sign in to rate this post

Topic: Ask a Rails expert / HTML to XML ---> get title & description

Hi, to all..

Dear friends ..i am fetching html page through net ..

Now i wanna take two things

1.title of the html page..

2.description of html page..

can any body help in that

 
Profile

Authority 0
Posting Rating 0
Sign in to rate this post

Topic: Ask a Rails expert / need your help or views for distributed programming with ruby

Erol,

true. I’d consider using threads (Yes, I know Ruby threads are not real threads…) but it has lesser overhead than DRb.
I LOVE DRb because it’s soooo simple yet powerful.

 
Profile

Authority 0
Posting Rating 0
Sign in to rate this post

Topic: Ask a Rails expert / how to refresh ruby files without restart production server

I have been using the gentle reload method :)

ps aux | grep ruby

Then kill -USR2 <pid> of the process in question. It reloads the files.

 
Profile

Authority 12
Posting Rating 0
Sign in to rate this post

Topic: Ask a Rails expert / Sensible number of mongrel instances...?

just to clear things up – is your app just storing the uploads or are you also performing resizing etc. on them ?

how high is the server load when passangers goes more or less down and how much memory is left ?

 
Profile

Authority 0
Posting Rating 33
Sign in to rate this post

Topic: Ask a Rails expert / Sensible number of mongrel instances...?

Hi All,

Just looking to see if anyone had any epiphanies over the last few weeks…? ;) I’m really at my wit’s end with this setup. So far I have Passenger with Enterprise Ruby running on the server. As stated, if I have less than 10 folks logged on, the application works just fine, but once I add another, it goes haywire. It might very well be an issue of too many images (about 250 per minute) being uploaded simultaneously. I’m guessing Passenger needs to spawn (or at the very least “fake”) 200 or so processes in order to handle this kind of traffic.

Upgrading the memory is somewhat a last resort as the hosting company charges an insanely expensive $29.99 PER MONTH for each extra gig of memory. Do you believe that going from 1 gig to 4 gigs (a.k.a. +$90/mth) is really the answer?

Based on the current suggestions, I believe I’m at peak performance. The only other thing I could think of would be to have a PHP script (or some other item in general) to handle ALL UPLOADS and leave RoR to handle only the end-user traffic. The only problem there is that I’ll eventually need RoR to handle the actual import into the DB, etc., but BackgroundDrb won’t play nicely on the server.

My apologies for beating a potentially dead horse. I’m just severely frustrated at this point and this is absolutely the best place I’ve found for bouncing my ideas (and by extension, beating dead horses ;) ).

Best!

 
Ernie

Authority 25
Posting Rating 99
Sign in to rate this post

Topic: General Discussion / [Noob] How RoR handles data normalization

Rails does not design your database for you. You’re free to normalize/denormalize your data as you see fit. Rails has rich support for associations which allows easy access to your model’s attributes, regardless of what table you store them in.

Update: It occurred to me that you may have come to this conclusion based on a discussion somewhere of Single Table Inheritance. In the event that you have multiple classes (models) that are all descendants of a common base class, then ActiveRecord will allow you to persist all of them in one database table, using a special column by default called (unsurprisingly) “type”. The string representation of the class name will be stored there.

So, for example, you may have a table called fruits with columns color and type, then you could have a model that looked like:

class Fruit < ActiveRecord::Base
end

and then stuff like:

class Apple < Fruit
end
class Banana < Fruit
end
class Orange < Fruit
end

And so on. Each of these could have their own custom methods but they’d be stored in the same table. The type column would contain “Apple,” “Banana,” “Orange” and so on, but color would be whatever you set it to.

 
Profile

Authority 0
Posting Rating 0
Sign in to rate this post

Topic: General Discussion / [Noob] How RoR handles data normalization

*NOTE: I am sorry if I am posting this in the wrong section, so please feel free to move this thread.

I have only lightly looked in to RoR for a couple months now. I stumbled upon something that seemed weird to me, but I am sure you guys can answer my questions pretty quickly.

It seems RoR does not normaliza data in the database, or at least from my understanding.

For example (probably not the best, but just go with it):

If I had a model called Fruit, that kept many stats on the fruit (fruit type, weight, cost, etc). I would probably have the fruit type as a integer that is a foreign key to another table. This other table would contain the columns (fruit_id, fruit_name).

From what I have learned about RoR, it would not create this second table, it would just store a string in the Fruit table (“apple”, “banana”). This doesn’t seem like the best way to handle this data.

What am I missing? Can anyone point me to a resource to understand this better?

 
Profile

Authority 0
Posting Rating 0
Sign in to rate this post

Topic: General Discussion / Whether it is possible to automated test the Ruby on Rails application using the QTP tool?

Hi All,

If anybody have idea about the QTP tool using the Ruby on Rails application ....

Whether it is possible to automated test the Ruby on Rails application using QTP tool?

Thanks 
Vadivel
 
Mikegunderloyheadshot

Authority 50
Posting Rating 90
Sign in to rate this post

Topic: Ask a Rails expert / seledted option for select_tag

You need to specify which option will be selected as part of the options_for_select, not as part of the select_tag.

Something like

<%=select_tag(‘name’, options_for_select({ :Relevance =>‘Relevant’,:Date=>‘Recent’}, params[:name].to_s)) %>

 
Profile

Authority 37
Posting Rating 3
Sign in to rate this post

Topic: Rails in the workplace / How did you get Rails through the door where you work?

RubyOnRails, i started on it by jan 2006 as an intermediate level programmer.
Best part is the place i used to work had only two religions PHP || RAILS so i had a easy time choosing rails.
Great, piece of framework (David work was enlighted…)

 
Warrior

Authority 12
Posting Rating 3
Sign in to rate this post

Topic: Ask a Rails expert / seledted option for select_tag

Hi iam using select_tag i want selected_option. i have made select
_tag like this

<%=select_tag(‘name’, options_for_select({ :Relevance =>‘Relevant’,:Date=>‘Recent’}),:selected=>params[:name].to_s) %>

The generated html look like this

<select name="name" id="name" selected="Relevant"><option value="Recent">Date</option>
<option value="Relevant">Relevance</option></select>

How to make the selected option inside option tag

 
Profile

Authority 25
Posting Rating 0
Sign in to rate this post

Topic: Ask a Rails expert / Merging fields from two tables into one, including duplicates

Hi,

I have two tables, nutritions and food_options.
nutritions has two fields, fooditem_id, taken and .
food_options has two fields, fooditem_id and taken.
fooditem_id in nutritions and food_options will point to id in food_items table(third table).

I want to select all records from nutritions and food_options into a new table, C with Fields fooditem_id and taken. This means I need to combine the values of fooditem_id in nutritions and fooditem_id in food_options into one field (fooditem_id), including the duplicates in both tables.

EX:
nutritions
id fooditem_id taken
1 23 1
2 23 1

food_options
id fooditem_id taken
1 34 1

C
id fooditem_id taken
1 23 1
2 23 1
3 34 1

How can I do this?

thanks,
srinath

 
Profile

Authority 12
Posting Rating 59
Sign in to rate this post

Topic: Ask a Rails expert / saving has_many :through

in the end I comed up with

def reason_attributes=(reason_attributes)
  reasons.clear
  reason_attributes.uniq.each do |reason|
    reasons << Reason.find_or_create_by_content(reason)
  end
end

this creates some problem on updating records, though.

you can find more informations about the issue here:
http://groups.google.com/group/rubyonrails-talk/browse_thread/thread/49ca7d933579dcd9#

thanks

 
Profile

Authority 12
Posting Rating 59
Sign in to rate this post

Topic: Ask a Rails expert / saving has_many :through

hi everyone,
I noticed a huge lack of informations or examples on how to properly save a has_many :through associated records without cluttering the controller.

What I’m doing is using complex forms, which are also covered in Ryan’s railscasts, and trying to adapt them to a hm:t situation instead of a simple has_many.

From my understanding there should be a callback that erases (in both cases, create/update) current associated objects and rebuilds new ones.

Given this:

class Report < ActiveRecord::Base
  has_many :report_reasons
  has_many :reasons, :through => :report_reasons #, :accessible => true

When creating or updating a Report I also include one or more Reason in the form, which is an associated object, my solution, which is ugly, is an after_save callback, keeping the controller clean as possible:

attr_accessor :new_reason_attributes
attr_accessor :existing_reason_attributes
after_save :build_reasons
protected
def build_reasons
  Report.transaction do
    reasons.clear
    unless new_reason_attributes.blank?
      new_reason_attributes.each do |new_reason|
        reasons << Reason.find_or_create_by_content(new_reason["content"])
      end
    end
    unless existing_reason_attributes.blank?
      existing_reason_attributes.each do |existing_reason|
        reasons << Reason.find_or_create_by_content(existing_reason1)
      end
    end
  end
end

Does anyone have better ideas?

 
Profile

Authority 0
Posting Rating 0
Sign in to rate this post

Topic: Ask a Rails expert / Use Rails to develop sites for both Designer and Programmer

Thank you for your answer.
And I have once more question.
How can I separate the views from many group user (base on UserAnget)?

 
Profile

Authority 50
Posting Rating 40
Sign in to rate this post

Topic: Ask a Rails expert / Ruby on Rails eCommerce

Start from scratch. Rails is made for people that loves to write awesome code, and if you love writing awesome code, you probably also love starting from scratch. Yes, you do have time to do that.

Next page

Pages: 1 2 3 4 5 6 7 8 9 10 11 ... 81

Recent Forum Topics

Couldn't find Product without an ID
in Ask a Rails expert

HTML to XML ---> get title & descri...
in Ask a Rails expert

Accessing controller actions from s...
in Ask a Rails expert

[Noob] How RoR handles data normali...
in General Discussion

Whether it is possible to automated...
in General Discussion

seledted option for select_tag
in Ask a Rails expert

Merging fields from two tables into...
in Ask a Rails expert

saving has_many :through
in Ask a Rails expert

Use Rails to develop sites for both...
in Ask a Rails expert

Rails+RS232
in Ask a Rails expert


Forum adapted from Beast. Original authors: © 2006 Josh Goebel Rick Olson