You are here: Forums Recent Posts
2,003 post(s) found
Pages: 1 2 3 4 5 6 7 8 9 10 11 ... 81
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. |
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 |
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 . |
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 |
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.
<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.
#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:
|
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!. Cheers!. |
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. I hope it help you |
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. |
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> if static_page here are the pasties: portion of scripted output: http://pastie.org/265913 Again, plese let me know if plain html works here. |
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..
Now i wanna take two things 1.title of the html page.. 2.description of html page.. can any body help in that |
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. |
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. |
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 ? |
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! |
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:
and then stuff like:
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. |
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? |
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,
Whether it is possible to automated test the Ruby on Rails application using QTP tool?
|
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)) %> |
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. |
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 <%=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 |
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. 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: food_options C How can I do this? thanks, |
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
this creates some problem on updating records, though. you can find more informations about the issue here: thanks |
Authority 12
Posting Rating 59
Sign in to rate this post
|
Topic: Ask a Rails expert / saving has_many :through hi everyone, 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:
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:
Does anyone have better ideas? |
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. |
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. |
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