[Rails] Re: Help with return_back

2009-02-14 Thread Chris Kottom
Based on the principle of least surprise, you've got two cases you need to
plan for:

   1. The user explicitly requests the login page, and so after a successful
   login, you send him back to the page he came from.
   2. The user requests a protected action that requires login, so you
   redirect to the login page and then, after successful login, take him to the
   originally-requested page.

To solve this, you need to store the after-login destination in a session
variable based on these rules and depending on whether you get to your login
page from a before filter method (classic name here in every example ever
written is authorize) or from an HTTP GET request for your login page.  In
either case, if the user succeeds in logging in and the variable is set,
reset the session variable and redirect to that location.  Otherwise,
redirect to a default location.

Hope this helps...


On Fri, Feb 13, 2009 at 9:22 PM, John Smith 
rails-mailing-l...@andreas-s.net wrote:


 I have to log in my app, after the login I want to return back to the
 page I was visiting just before the redirect to the login. Now, I have
 this in my Sessions controller:
  redirect_back_or_default('/')
 --
 Posted via http://www.ruby-forum.com/.

 


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To post to this group, send email to rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~--~~~~--~~--~--~---



[Rails] Re: Auto_complete plugin in Rails 2.2.2 (auto_complete_for method not found)

2009-02-14 Thread Spiros K.

Thanks for your reply,
but

1. this specific plugin did not have an install.rb with it.
2. 2.2.2 is as new as they get I just downloaded 3 weels ago...?! And
i think it works just fine with git as I have downloaded from git as
well (though it messed my tortoise svn structure pretty badly)

Then fired up my script/server and still:

method not found for autocomplete_for method!!! :-(


On Feb 13, 12:55 pm, Frederick Cheung frederick.che...@gmail.com
wrote:
 On 13 Feb 2009, at 09:19, Spiros K. wrote:

  page not found error

  * Trying to manually copy the files in the vendor/plugin directory of
  my project (got them from the model_auto_completer example), but still
  does not work... (if i execute script/plugin list there is nothing)

  Regarding this last part, i have been trying to find documentation
  about how to manually install a plugin, but with no results. In every
  forum that someone asks how to do it manually people respond with
  script/plugin install. This is automatic, not manually, as i am sure
  most of you know. What i am searching for is instructions on: where to
  place the files myself and what to execute myself so that my project
  will 'use' the plugin.

 Copying the files into vendor/plugins is all there is to it 99% of the  
 time. Some plugins have an install.rb file that needs to be run after  
 this.
 Don't worry about the output of script/plugin list (which as far as I  
 can tell is for listing available, not installed plugins)

 The autocomplete plugin is on github these 
 days:http://github.com/rails/auto_complete/tree/master

 Newer versions of rails include a version of script/plugin that can  
 install plugins from git repositories (assuming you have git itself of  
 course).

 Fred





  I will be thankful for any help you might offer, no matter how small,
  but PLEASE don't repeat to me steps i have already taken with no
  differentation what-so-ever. This is both pointless and insulting.

  Yours sincerely,
  a frustrated RoR programmer
  Spiros K.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To post to this group, send email to rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~--~~~~--~~--~--~---



[Rails] Re: Odd js behavior in Chrome Safari

2009-02-14 Thread chauzer

I ran into this same issue, it has nothing to do with Rails.  This
looks to be an issue with the way WebKit (used by Safari and Chrome)
handles javascript and form submits.  Looks like if there is a onclick
on a submit button, data from the form is not submitted when the page
is posted.

On Dec 24 2008, 2:49 am, Ken Wagner rails-mailing-l...@andreas-s.net
wrote:
 View file has a js function confirm_result() in head section:

 script type=text/javascript
     function confirm_action()
     {
       result = confirm(Please select OK or Cancel)
       if (result == true)
         document.write(You selected OK.)
       else
         document.write(You selected Cancel.)
     }
   /script

 The body section has

 input type=button onclick=confirm_action() value=Submit

 Works just fine in IE7 and FireFox3.

 But not in Chrome 1 or Safari 3. In the latter two the confirm box
 appears, then a new blank page without the You selected...  text. Js
 otherwise working fine

 Has anyone else encountered this? Bug in Rails? Chrome? Safari?
 --
 Posted viahttp://www.ruby-forum.com/.

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To post to this group, send email to rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~--~~~~--~~--~--~---



[Rails] Undefined method 'parameters' on controller.request

2009-02-14 Thread Michael J. I. Jackson

I'm getting a NoMethodError using Rails 2.1.0 when trying to send an  
email using ActionMailer. The error is being thrown from the  
template_format method in ActionView's base.rb file. Apparently the  
controller.request object is an instance of DummyClass (according to  
the exception trace) instead of ActionController::Request, and  
therefore does not have any useful methods associated with it.

Right now I'm thinking that because the ActionMailer doesn't actually  
represent a separate request per se, that the request object is not  
being created correctly. Thus, when it goes to create the email using  
the template, it doesn't really know what format to use. Just a hunch.

I'm kind of a Rails newb, so any help with this issue would be greatly  
appreciated. Just let me know if you need to know any other information.

Michael


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To post to this group, send email to rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~--~~~~--~~--~--~---



[Rails] Re: How to stop validating after a failed validation?

2009-02-14 Thread Frederick Cheung



On Feb 13, 11:29 pm, ericindc ericmilf...@gmail.com wrote:
 I want my first check to verify email address uniqueness.  If this
 validation fails, there's no reason to go further with validating the
 user's input.  I want a singular message displayed in this case.  Is
 there a way to do this?

I think the best way would be to use your own function (instead of
error_messages_for) for displaying the error. You might also be able
to get somewhere with the  :if option to validations (and have your if
function check whether there are any errors yet). While the examples
you provide are interesting, more generally it is really annoying as a
user to have to correct form errors once at a time.

Fred

 Also, what about group validations, such that, for example, if I have
 several checks on a password (existence, complexity, confirmation) and
 one fails, the others are ignored.  So for instance, if the password
 field does not match its confirmation, I skip validating the password
 complexity.

 What's the best approach to this?  Thanks.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To post to this group, send email to rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~--~~~~--~~--~--~---



[Rails] Re: params

2009-02-14 Thread Frederick Cheung



On Feb 14, 6:36 am, Vetrivel Vetrivel rails-mailing-l...@andreas-
s.net wrote:
 How to convert params variable as hash.I am not able to convert params
 as a hash.

If you are talking about the params variable you get in your
controller actions, it's already a hash. Perhaps you can clarify what
you're trying to do and the problem you have encountered?

Fred
 --
 Posted viahttp://www.ruby-forum.com/.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To post to this group, send email to rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~--~~~~--~~--~--~---



[Rails] Re: association include and joins issues - 'Unknown Column' error

2009-02-14 Thread Frederick Cheung



On Feb 14, 12:43 am, Chris csw11...@gmail.com wrote:
 Hi all,

 I'd really appreciate any help / advice on this problem. When I test
 this

   def edit
     @entity = Entity.find(params[:id],
                           :include = :key_factors)
     @traits = Trait.find :all,
                          :include = :trait_values,
                          :joins = :trait_values,
                          :joins = LEFT OUTER JOIN key_factors ON
 key_factors.trait_value_id = trait_values.id AND
 key_factors.entity_id=+...@entity.id.to_s,
                          :order = 'traits.ordering, traits.name'
     @frequencies = Frequency.find :all,
                                   :order = 'value'
   end

 I get the error ActiveRecord::StatementInvalid: Mysql::Error: Unknown
 column 'trait_values.id' in 'on clause': SELECT `traits`.* FROM
 `traits`  LEFT OUTER JOIN key_factors ON key_factors.trait_value_id =
 trait_values.id AND key_factors.entity_id=953125641. I would have
 thought that since I'm including trait_values then that table would be
 in the SQL statement. However, what I see in the development log is:

   [4;36 Entity Load (0.0ms)   SELECT * FROM `entities` WHERE
 (`entities`.`id` = 1)
   [4;35 KeyFactor Load (0.0ms) SELECT `key_factors`.* FROM
 `key_factors` WHERE (`key_factors`.entity_id = 1)
   [4;36 Trait Load (0.0ms)Mysql::Error: Unknown column
 'trait_values.id' in 'on clause': SELECT `traits`.* FROM `traits` LEFT
 OUTER JOIN key_factors ON key_factors.trait_value_id = trait_values.id
 AND key_factors.entity_id=1 ORDER BY traits.ordering, traits.name

 Which suggests that Rails is doing a separate call for each include...
 and a bit of research on the API confirms that. However, in an earlier
 version of rails this worked fine - the log for running the exact same
 code shows (more or less - replaced a long field list with '*' to make
 reading easier)

Yup that is what happens. It should fall back to the old code in cases
like this however I suspect that it doesn't check the :joins clause
for tables for that need to be included in the old way.
I'm assuming you do actually want that include (and that it wasn't
just an easy way of triggering a join) since the answer is probably a
lot easier if you don't need the include.
Rails will fall back to the old code whenever it sees something that
looks like you're using a table that isn't the base table or provided
through the joins clause. As I said, unfortunately I don't think it
checks the join clause in this way for references to tables.

You should be able fix it by adding a dud condition that references
the included table. I suspect it was just you poking around but doing

:joins = :trait_values,
:joins = LEFT OUTER JOIN key_factors ON  ... 

doesn't do anything since a hash  can only have one value for a given
key.
YOu could also try

:joins = INNER JOIN trait_values ON ... LEFT OUTER JOIN key_factors
ON  ... 

This would allow the query to run ok, however I suspect it would still
process the include off the back of a second query.

Fred

   [4;36 Trait Load Including Associations (0.00) SELECT * FROM
 traits LEFT OUTER JOIN trait_values ON trait_values.trait_id =
 traits.id LEFT OUTER JOIN key_factors ON key_factors.trait_value_id =
 trait_values.id AND key_factors.entity_id=1 ORDER BY traits.ordering,
 traits.name

 My models are:

 class Trait  ActiveRecord::Base
   has_many :trait_values, :dependent = :destroy
 end

 class TraitValue  ActiveRecord::Base
   belongs_to :trait
   has_many :key_factors, :dependent = :destroy
   has_many :trait_value_images, :foreign_key =
 'related_id', :dependent = :destroy

   def sorter
     [(self.trait.ordering || 0),(self.trait.name || 0),
 (self.ordering || 0),(self.name || )]
   end

 end

 The API suggests that having conditions on a has_many association
 might do the trick, but the condition would be to be able to be
 dynamically specified (...key_factors.entity_id=+...@entity.id.to_s)
 and I don't see how that's possible when defining the condition on the
 association in the model (not sure whether that's because it actually
 isn't possible or just because I don't know Rails well enough).

 Please help!

   -Chris Warren
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To post to this group, send email to rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~--~~~~--~~--~--~---



[Rails] Re: Eager fetching returning JSON results

2009-02-14 Thread Frederick Cheung



On Feb 14, 1:26 am, Joshua Partogi joshua.j...@gmail.com wrote:
 All,

 I have a many_to_one relationship object between products and
 categories and I want to return the category too using JSON results
 but it seems that rails only gives back the products JSON object on
 the view layer. This is the piece of code:

         @products = Product.find(:all, :include = [:category] )

         respond_to do |format|
             format.json {render :json = [...@products]
         end

There's 2 separate things: the :include option on Product.find just
ensures those associations are loaded
To have them in your json (or xml) output you need to pass that to
to_json or to_xml, ie render :json = @products.to_json(:include
= :category)

Fred

 Have I missed something? I thought by doing this I have enabled the
 eager fetching? Or does eager fetching does not work with JSON
 results?

 Thanks in advance.

 --
 If you can't believe in God the chances are your God is too small.

 Read my blog:http://joshuajava.wordpress.com/
 Follow me on twitter:http://twitter.com/jpartogi
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To post to this group, send email to rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~--~~~~--~~--~--~---



[Rails] Re: Observe Field Problem

2009-02-14 Thread Frederick Cheung



On Feb 13, 11:39 pm, Enzo Rivello rails-mailing-l...@andreas-s.net
wrote:
 Hi there!

 I need to use observe field to change dynamically one select field based
 on another select field:

 here is the view:

 %= observe_field 'class', :url = { :action = 'update_list' },
           :frequency = 0.25,
           :update = 'nickname',
                       :with = 'tipid'
           %

 Class:select name=%= #{name}[][#{name}_class] % id=class
       %= options_from_collection_for_select(Tiprod.find(:all),
 id,name, {:include_blank = true}) %
       /select
 Name:select name=%= #{name}[][#{name}_data] % id=nickname
       option/option
                         /select

 here is the controller

 def update_list
   @tipid = params[:tipid]
   @products = Specprod.find(:all, :conditions = ['tiprif LIKE ?',
 %...@tipid}%])
 end

 and here is the update_list.rhtml

 % for product in @products%
   option value=%= product.id %%= product.name%/option
 % end %

 inspired 
 by:http://nealenssle.com/blog/2007/04/12/how-to-dynamically-update-form-...



The observe_field helper just produces some javascript that does stuff
to the element with id class

You've got the call to observe_field before your select element, ie
it's trying to observe something that doesn't exist yet.

Fred

 Now, when i try to fire this application, the script doesn't work, and
 the JS console tell me Element is null .
 Why?Where i was wrong?

 thanks in advance for the help
 --
 Posted viahttp://www.ruby-forum.com/.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To post to this group, send email to rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~--~~~~--~~--~--~---



[Rails] Re: Auto_complete plugin in Rails 2.2.2 (auto_complete_for method not found)

2009-02-14 Thread Frederick Cheung



On Feb 14, 9:58 am, Spiros K. spiros...@gmail.com wrote:
 Thanks for your reply,
 but

 1. this specific plugin did not have an install.rb with it.
 2. 2.2.2 is as new as they get I just downloaded 3 weels ago...?! And
 i think it works just fine with git as I have downloaded from git as
 well (though it messed my tortoise svn structure pretty badly)

so is the plugin in vendor/plugins ?
 Then fired up my script/server and still:

 method not found for autocomplete_for method!!! :-(

I also assume that that was a typo and you actually write
auto_complete_for in your controller.

Fred

 On Feb 13, 12:55 pm, Frederick Cheung frederick.che...@gmail.com
 wrote:

  On 13 Feb 2009, at 09:19, Spiros K. wrote:

   page not found error

   * Trying to manually copy the files in the vendor/plugin directory of
   my project (got them from the model_auto_completer example), but still
   does not work... (if i execute script/plugin list there is nothing)

   Regarding this last part, i have been trying to find documentation
   about how to manually install a plugin, but with no results. In every
   forum that someone asks how to do it manually people respond with
   script/plugin install. This is automatic, not manually, as i am sure
   most of you know. What i am searching for is instructions on: where to
   place the files myself and what to execute myself so that my project
   will 'use' the plugin.

  Copying the files into vendor/plugins is all there is to it 99% of the  
  time. Some plugins have an install.rb file that needs to be run after  
  this.
  Don't worry about the output of script/plugin list (which as far as I  
  can tell is for listing available, not installed plugins)

  The autocomplete plugin is on github these 
  days:http://github.com/rails/auto_complete/tree/master

  Newer versions of rails include a version of script/plugin that can  
  install plugins from git repositories (assuming you have git itself of  
  course).

  Fred

   I will be thankful for any help you might offer, no matter how small,
   but PLEASE don't repeat to me steps i have already taken with no
   differentation what-so-ever. This is both pointless and insulting.

   Yours sincerely,
   a frustrated RoR programmer
   Spiros K.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To post to this group, send email to rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~--~~~~--~~--~--~---



[Rails] Re: Logging all exceptions

2009-02-14 Thread koopmann.lenn...@googlemail.com

On 14 Feb., 03:56, Robby Russell ro...@planetargon.com wrote:
 You might consider using Exceptional for this.

 *http://getexceptional.com/

Thank you, Robby. The problem is that I want to build the database
exception logging into the Rails web interface of a free software
project. (www.scopeport.org)
I don't want to force users to subscribe to another service if they
want help. (But Exceptional looks very cool. I might consider using it
for other projects)

I will take a look at the callback thing. Thank you pepe.

So long
Lennart
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To post to this group, send email to rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~--~~~~--~~--~--~---



[Rails] Re: How can I retrieve the SQL during each model action?

2009-02-14 Thread Mark Reginald James

xeon wrote:
 Hi,
 
 I would like to know for each running model action, how can I retrieve
 the SQL running behind? I don't want to scan log each time for the sql
 running behind.
 E.g. post.find(:all,:conditions={:id='1'}
 
 I wanna debug the sql generated behind, is that other shorthand
 function like post.find().show_sql() that enable
 us to view what's SQL generated ?

That sounds like a good idea. Perhaps a
:log = :instance_variable_name option to find.

One alternative is the query_trace plugin that displays
a backtrace for each query, so that the log shows what
line of code is associated with each query.

-- 
Rails Wheels - Find Plugins, List  Sell Plugins - http://railswheels.com

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To post to this group, send email to rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~--~~~~--~~--~--~---



[Rails] Re: Redirect_to Vs Render_component

2009-02-14 Thread Mark Reginald James

Srividya Sharma wrote:
 Hello
 I am using Rails 2.2.2.
 Here is my problem:
 I have a controller action which will receive several parameters,
 validate them, process them and create a new set of parameters out of
 them.
 Then, this controller should delegate the task to another controller
 action based on some values and pass these processed parameters to it. I
 have stored the processed parameters in a hash. (there are many of them)
 
 I could only see two options to achieve this:
 1. Use redirect_to and pass each parameter as a string.
 2. Use render_component and pass the parameters as a hash.
 
 I have seen that render_component is not recommended in most cases. Is
 it recommended solution for this case? I think render_component slows
 down the request also.
 Which option is right for me?
 Are there any other ways to achieve this? Please guide me.

If you don't want the browser url to change, you can just call
the other action like a method, passing the parameters in either
an instance variable or a method parameter (that's default nil
to allow it to be called externally). Or are you messing with
params directly?

This is assuming the other method is in the same controller.
If it isn't, you'll have to make the other method available
within the first controller, either through inheritance or
mix-ins.

-- 
Rails Wheels - Find Plugins, List  Sell Plugins - http://railswheels.com

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To post to this group, send email to rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~--~~~~--~~--~--~---



[Rails] Re: NoMethodError in User_photos#show

2009-02-14 Thread Frederick Cheung



On Feb 14, 3:32 am, Ken Lim rails-mailing-l...@andreas-s.net wrote:
 MaD wrote:
  well, the error-message is pretty clear:
  The error occurred while evaluating nil.user
  2: %= link_to #...@photo.user.username}'s Photos,

  @photo seems to be nil. the reason for it can be found in your
  controller (where show is defined).

 I still have no clue at all as I follow the code from the book. The
 application trace state that the respond to do |format| in the show
 method has something wrong.

 Below is controller where show is defined:

Not necessarily. For example if the link you generated was not quite
right so that params[:user_id] or params[:id] were not correct then
Photo.find_by_user_id_and_id might quite legitimately return nil.

Fred

 Class UserPhotosController  ApplicationController
   before_filter :login_required, :except = [:index, :show]

   def index
     @user = User.find(params[:user_id])
     @photo_pages = Paginator.new(self, @user.photos.count, 9,
 params[:page])
     @photos = @user.photos.find(:all, :order = 'created_at DESC',
                                       :limit =
 @photo_pages.items_per_page,
                                       :offset =
 @photo_pages.current.offset)
     respond_to do |format|
       format.html # index.rhtml
       format.xml { render :xml = @photos.to_xml }
     end
   end

   def show
     @photo = Photo.find_by_user_id_and_id(params[:user_id],
                                           params[:id],
                                           :include = :user)

     respond_to do |format|
       format.html # show.rhtml
       format.xml { render :xml = @photo.to_xml }
     end
   end
   .
   .
   .

 Attachments:http://www.ruby-forum.com/attachment/3296/user_photos_controller.rb

 --
 Posted viahttp://www.ruby-forum.com/.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To post to this group, send email to rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~--~~~~--~~--~--~---



[Rails] Re: Redirect_to Vs Render_component

2009-02-14 Thread Srividya Sharma

Nice to see a response. The other method is in another controller. And 
the other method needs to use send_data. (basically write a response)
So I cannot use a simple class, include that class in the first 
controller.
since the other method has to write out a response, it needs to be in 
another controller.(I hope I am right about this)

In the first controller, the request parameters are processed and these 
processed parameters need to be passed to the other method in the other 
controller.

Mark Reginald James wrote:
 Srividya Sharma wrote:
 I could only see two options to achieve this:
 1. Use redirect_to and pass each parameter as a string.
 2. Use render_component and pass the parameters as a hash.
 
 I have seen that render_component is not recommended in most cases. Is
 it recommended solution for this case? I think render_component slows
 down the request also.
 Which option is right for me?
 Are there any other ways to achieve this? Please guide me.
 
 If you don't want the browser url to change, you can just call
 the other action like a method, passing the parameters in either
 an instance variable or a method parameter (that's default nil
 to allow it to be called externally). Or are you messing with
 params directly?
 
 This is assuming the other method is in the same controller.
 If it isn't, you'll have to make the other method available
 within the first controller, either through inheritance or
 mix-ins.
 
 --
 Rails Wheels - Find Plugins, List  Sell Plugins - 
 http://railswheels.com

-- 
Posted via http://www.ruby-forum.com/.

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To post to this group, send email to rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~--~~~~--~~--~--~---



[Rails] can this be done without using find_by_sql

2009-02-14 Thread tonypm

Hi,

I am increasingly needing to do some more complex finds involving
several table associations.  I can usually find an SQL solution, but
find it hard to think these out using ActiveRecord find techniques.  I
guess I am thinking in SQL terms, when perhaps there is a way of
thinking in ActiveRecord terms.  Here is an example, I am guessing
this can be done without using find_by_sql

Repair has_many :notes

SELECT * FROM repairs
where exists
(select * from notes where repairs.id=notes.repair_id
   and  and notes.flagged)

Thanks
Tonypm
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To post to this group, send email to rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~--~~~~--~~--~--~---



[Rails] Re: Suggestions for a rails webhost...

2009-02-14 Thread tonypm

Peter,

  The dramatic
 improvement in ping time does make quite a difference to be honest,

Confirms what I was what I was wondering about.

Had a look at bytemark, they look worth following up.

Thanks
Tonypm


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To post to this group, send email to rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~--~~~~--~~--~--~---



[Rails] Re: can this be done without using find_by_sql

2009-02-14 Thread Frederick Cheung


On 14 Feb 2009, at 11:33, tonypm wrote:


 Hi,

 I am increasingly needing to do some more complex finds involving
 several table associations.  I can usually find an SQL solution, but
 find it hard to think these out using ActiveRecord find techniques.  I
 guess I am thinking in SQL terms, when perhaps there is a way of
 thinking in ActiveRecord terms.  Here is an example, I am guessing
 this can be done without using find_by_sql

 Repair has_many :notes

 SELECT * FROM repairs
 where exists
 (select * from notes where repairs.id=notes.repair_id
   and  and notes.flagged)


Well at a very basic level you could do Repair.find :all, :conditions  
= exists (select ...)
but that doesn't gain you much.

You could write

Repair.find :all, :select = 'distinct repairs.*', :joins  
= :notes, :conditions = [flagged = ?, true]

or something along those lines.

Fred

 Thanks
 Tonypm
 


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To post to this group, send email to rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~--~~~~--~~--~--~---



[Rails] Re: can this be done without using find_by_sql

2009-02-14 Thread Phlip

tonypm wrote:

 Repair has_many :notes
 
 SELECT * FROM repairs
 where exists
 (select * from notes where repairs.id=notes.repair_id
and  and notes.flagged)

   r = Repair.find(...)
   notes = r.notes.find_by_flagged(true)

I can't think of a way to learn how deep the ActiveRecord DSL gets, besides 
read 
read read blogs, tutorials, books, and its documentation! I myself probably 
know 
only 30% of it!

-- 
   Phlip


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To post to this group, send email to rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~--~~~~--~~--~--~---



[Rails] Re: NoMethodError in User_photos#show

2009-02-14 Thread MaD

two suggestions:
1. set a debugger at the beginning of you show-method. that way you
will find the reason for @photo being nil.
2. since Photo.id is your primary key (and therefore unique) you could
just do your find like this:
  @photo = Photo.find(params[:id])
instead of the much longer:
  @photo = Photo.find_by_user_id_and_id(params[:user_id], params
[:id], :include = :user)
as long as id distinctly identifies the record the user_id doesn't
matter.

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To post to this group, send email to rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~--~~~~--~~--~--~---



[Rails] Re: can this be done without using find_by_sql

2009-02-14 Thread Phlip

Frederick Cheung wrote:

 Repair has_many :notes

 SELECT * FROM repairs
 where exists
 (select * from notes where repairs.id=notes.repair_id
   and  and notes.flagged)

I forgot my basic SQL! I think that's just

  SELECT * FROM repairs r, notes n
   WHERE r.id = n.repair_id
 AND n.flagged = 1

right?

   Repair.all( :include = :notes,
:conditions ={ 'notes.flagged' = true } )

Find all repairs with any flagged notes. And I thought AR would handle 
distinct-ing that.

So how to do a sub-select if you indeed need one?

But my other answer lets you trivially walk back from the notes to the repairs:

   r.notes.find_by_flagged(true).map(:repair)

Warning: A map{} that rips another model like that can grow inefficient!

-- 
   Phlip


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To post to this group, send email to rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~--~~~~--~~--~--~---



[Rails] Re: Eager fetching returning JSON results

2009-02-14 Thread Joshua Partogi

Darn,

I returned an array object besides that products instance, giving that
to_json will give backslashes to the quotes.

On Feb 14, 9:31 pm, Frederick Cheung frederick.che...@gmail.com
wrote:
 On Feb 14, 1:26 am, Joshua Partogi joshua.j...@gmail.com wrote: All,

  I have a many_to_one relationship object between products and
  categories and I want to return the category too using JSON results
  but it seems that rails only gives back the products JSON object on
  the view layer. This is the piece of code:

          @products = Product.find(:all, :include = [:category] )

          respond_to do |format|
              format.json {render :json = [...@products]
          end

 There's 2 separate things: the :include option on Product.find just
 ensures those associations are loaded
 To have them in your json (or xml) output you need to pass that to
 to_json or to_xml, ie render :json = @products.to_json(:include
 = :category)

 Fred

  Have I missed something? I thought by doing this I have enabled the
  eager fetching? Or does eager fetching does not work with JSON
  results?

  Thanks in advance.

  --
  If you can't believe in God the chances are your God is too small.

  Read my blog:http://joshuajava.wordpress.com/
  Follow me on twitter:http://twitter.com/jpartogi
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To post to this group, send email to rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~--~~~~--~~--~--~---



[Rails] Re: How to stop validating after a failed validation?

2009-02-14 Thread ericindc

Thanks for the response.

I'm still not sure how I'll approach this.  I'm going to spend a bit
of time tinkering with the :if option, as well as creating my own
validation function.  I agree that it is annoying for the user to have
to correct errors one at a time.  But I'd imagine correcting a series
of errors, just to finally realize that the email address has already
been registered, might be equally as annoying.  Hence why I want the
email uniqueness check to be first and foremost.  If their email
address has been used, the rest of the validation errors become moot.

On Feb 14, 5:16 am, Frederick Cheung frederick.che...@gmail.com
wrote:
 On Feb 13, 11:29 pm, ericindc ericmilf...@gmail.com wrote:

  I want my first check to verify email address uniqueness.  If this
  validation fails, there's no reason to go further with validating the
  user's input.  I want a singular message displayed in this case.  Is
  there a way to do this?

 I think the best way would be to use your own function (instead of
 error_messages_for) for displaying the error. You might also be able
 to get somewhere with the  :if option to validations (and have your if
 function check whether there are any errors yet). While the examples
 you provide are interesting, more generally it is really annoying as a
 user to have to correct form errors once at a time.

 Fred



  Also, what about group validations, such that, for example, if I have
  several checks on a password (existence, complexity, confirmation) and
  one fails, the others are ignored.  So for instance, if the password
  field does not match its confirmation, I skip validating the password
  complexity.

  What's the best approach to this?  Thanks.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To post to this group, send email to rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~--~~~~--~~--~--~---



[Rails] Re: can this be done without using find_by_sql

2009-02-14 Thread tonypm

Just to finish the story.

Sorry -  the distinct in the select is needed, I missed it out.

Going a step further, I now have:

named_scope :flagged_repairs, :select = 'distinct repairs.*', :joins
= :repair_notes, :conditions = [notes.flagged = ?, true]

So in my search, where I am building a dynamic scope (thanks to
railscasts)
I can do:

scope.flagged_repairs.paginate(:page=page, :per_page=per_page)

And it all appears to work!!

Incredibly neat

Tonypm


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To post to this group, send email to rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~--~~~~--~~--~--~---



[Rails] Re: attachment_fu problems with image_science

2009-02-14 Thread Tod Mcintyre

Richard Schneeman wrote:
 
 
 Danimal wrote:
 Richard,
 
 I am having exactly the same problem. Everything works on my macbook
 pro. But on my deployment server I get the same error.
 
 I'm still looking. Hopefully I can find a solution. Like you, I'm
 having trouble with RMagick. Plus I like Image Magick because it's so
 much slimmer (and I only need thumbnailing).
 
 -Danimal
 
 On May 28, 10:53 pm, Richard Schneeman rails-mailing-l...@andreas-
 
 my problem ended up being with my ruby gems path on my server, which can 
 have many many causes. remember whenever you require RMagick that you 
 capitalize RM, because gems are case sensitive. If you go into your irb, 
 and type require rubygems and then require RMagick what do you get??

I'm having the EXACT same problem.  Tried everything to get RMagick to 
work and I could never get require 'RMagick' to work.  So, I uninstalled 
everything RMagick related and tried to switch to image_science, since 
it seems to be more lightweight anyway.  but require 'image_science' 
didn't work

After reading your post I just tried require 'rubygem' THEN require 
'image_science' and it worked!  What does this mean though? How can I 
get the rubygems in the right path so that all my gems are accessible be 
default.  Do I need to worry about this with rails?  I would think rails 
would run similarly to irb and would thus need rubygems included 
somehow?  I haven't put my server in production yet (or even deployed my 
first rails app) so I haven't tested anything.
-- 
Posted via http://www.ruby-forum.com/.

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To post to this group, send email to rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~--~~~~--~~--~--~---



[Rails] Re: can this be done without using find_by_sql

2009-02-14 Thread tonypm

Fred,

Repair.find :all, :select = 'distinct repairs.*', :joins
= :notes, :conditions = [flagged = ?, true]

nice - many thanks.  just needed to fix notes.flagged
--

In reality I have a generic notes model, so my usage is slightly more
complex:

In Repair I have:

has_many :repair_notes, :foreign_key='note_for'
 
has_many :flagged_repair_notes, :class_name=RepairNote, 
:foreign_key='note_for',
   :conditions={:flagged=true}

Then:

Repair.find :all, :select = 'repairs.*', :joins
= :repair_notes, :conditions = [notes.flagged = ?, true]

Creates lovely sql

SELECT repairs.* FROM `repairs` INNER JOIN `notes` ON notes.note_for =
repairs.id AND (`notes`.`type` = 'RepairNote' ) WHERE (notes.flagged =
1)

I wonder if there is a  way to use the flagged_repair_notes in the
find for flagged repairs.

ps.
I have real admiration for the guys who do the ActiveRecord SQL
generation magic.

Thanks to all
Tonypm
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To post to this group, send email to rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~--~~~~--~~--~--~---



[Rails] about validate

2009-02-14 Thread Mike75

hello..

I am new to Ruby on Rails.. (2.2)
I am currently following steps from the book agile web delopment with
Rails building depot application.

It says I need to edit app/models/product.rb file and add the
following lines to check the price to be at least a cent.. that's 0.01


def price_must_be_at_least_a_cent
errors.add(:price, 'should be at least 0.01' ) if price.nil? ||
price  0.01
end


after this,  I typed 0.1 and 0.10, and get the error.. saying should
be at least 0.01..
if I type 1, or 0.01.. I don't get the error.

am I the only one with this problem? if so, i'd like to know what I
need to do to fix the problem.

thanks

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To post to this group, send email to rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~--~~~~--~~--~--~---



[Rails] Re: BackgroundRB persistant job table not created

2009-02-14 Thread Ratnavel P S

I use rails 2.2.2
Backgroundrb version (latest from svn)
-- 
Posted via http://www.ruby-forum.com/.

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To post to this group, send email to rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~--~~~~--~~--~--~---



[Rails] Re: about validate

2009-02-14 Thread MaD

i just tried it for myself. it's working correctly. so i advice to put
a debugger at the beginning of your action and look what you are
getting for price and where the error occurrs (whether it's inside
that method or even before).
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To post to this group, send email to rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~--~~~~--~~--~--~---



[Rails] BackgroundRB persistant job table not created

2009-02-14 Thread Ratnavel P S

Hi,

I have used backgroundrb plugin in my application,

I followed the tutorial in,
http://backgroundrb.rubyforge.org/

Everything works fine,
When I run rake backgroundrb:setup,
It created the required scripts, and backgroundrb.yml but the mirgation
files were missing.

Can some one help me out y this happened or with providing the default
miration file which it generates,

Regards,
Ratnavel.
-- 
Posted via http://www.ruby-forum.com/.

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To post to this group, send email to rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~--~~~~--~~--~--~---



[Rails] Hook Exist in Rails for System-Wide Exception Logging?

2009-02-14 Thread Peter Alvin

On our production servers, I'd like all exceptions to be automatically
logged to the database.

In other C# project I wrote that meant putting a try/catch in every
entry point method with the catch calling a generic routine which did
the INSERT into exceptions... SQL statement.

How do I do this in rails?  It would be nice if in application.rb or
even in each controller you could do:

exception_logger :my_exception_logger

Perhaps this could be implemented using filters?  Hopefully rails
already has this exact functionality built-in as I'd imagine everyone
would need it?

Pete
-- 
Posted via http://www.ruby-forum.com/.

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To post to this group, send email to rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~--~~~~--~~--~--~---



[Rails] Re: Schedule job in rails

2009-02-14 Thread Randy Kramer

On Saturday 14 February 2009 12:52 am, Valentino Lun wrote:
 Is it possible to do this in my crontab as follow?
 
 10 10 * * * wget http://localhost:3000/cron/someaction para1 para2

I'm not sure, but an alternative is to put the wget command in a small 
shell script (Linux talk, iiuc) or a .bat file (MS talk, iiuc).  Then 
invoke that shell script or .bat file from cron.

Randy Kramer
-- 
I didn't have time to write a short letter, so I created a video 
instead.--with apologies to Cicero, et.al.

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To post to this group, send email to rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~--~~~~--~~--~--~---



[Rails] Re: AR_Mailer Problem

2009-02-14 Thread Borja Martín

which ruby version are you using? I think I had a similar problem
using ruby 1.8.7 and solving it by downgrading to 1.8.6...



On Fri, Feb 13, 2009 at 5:23 PM, Sean McGilvray smcgilv...@gmail.com wrote:

 Hi all,

 I am using ar_mailer for sending newsletter. I got mails queued in
 emails table. However when running ar_sendmail to begin sending the
 mails, an exception is thrown:

 Unhandled exception wrong number of arguments (7 for 6)
 (ArgumentError):
/usr/lib/ruby/gems/1.8/gems/ar_mailer-1.3.1/lib/action_mailer/
 ar_sendmail.rb:408:in `start'
/usr/lib/ruby/gems/1.8/gems/ar_mailer-1.3.1/lib/action_mailer/
 ar_sendmail.rb:408:in `deliver'
/usr/lib/ruby/gems/1.8/gems/ar_mailer-1.3.1/lib/action_mailer/
 ar_sendmail.rb:500:in `run'
/usr/lib/ruby/gems/1.8/gems/ar_mailer-1.3.1/lib/action_mailer/
 ar_sendmail.rb:496:in `loop'
/usr/lib/ruby/gems/1.8/gems/ar_mailer-1.3.1/lib/action_mailer/
 ar_sendmail.rb:496:in `run'
/usr/lib/ruby/gems/1.8/gems/ar_mailer-1.3.1/lib/action_mailer/
 ar_sendmail.rb:340:in `run'
/usr/lib/ruby/gems/1.8/gems/ar_mailer-1.3.1/bin/ar_sendmail:5
/usr/bin/ar_sendmail:19:in `load'
/usr/bin/ar_sendmail:19

 I am using ar_mailer version 1.3.1.

 I know the solution is this below:

 The solution is: make them match either by providing the all required
 arguments or delete those unavailable arguments (for you) in the
 ar_sendmail function.

 How exactly do I fix this error.  I am new to RoR.  Can someone give
 me the steps to modify the environment file please.

 Thank you,

 Sean McGilvray
 




-- 
/**
 * dagi3d v4 | http://dagi3d.net
 */

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To post to this group, send email to rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~--~~~~--~~--~--~---



[Rails] Re: Undefined method 'parameters' on controller.request

2009-02-14 Thread Julian Leviston

Actionmailer is a bit different because the mail has it's own view  
which has no controller. You'd have to pass the controller in through  
the message to the mail when you're delivering or building it.

Blog: http://random8.zenunit.com/
Learn rails: http://sensei.zenunit.com/

On 14/02/2009, at 9:10 AM, Michael J. I. Jackson  
mjijack...@gmail.com wrote:


 I'm getting a NoMethodError using Rails 2.1.0 when trying to send an
 email using ActionMailer. The error is being thrown from the
 template_format method in ActionView's base.rb file. Apparently the
 controller.request object is an instance of DummyClass (according to
 the exception trace) instead of ActionController::Request, and
 therefore does not have any useful methods associated with it.

 Right now I'm thinking that because the ActionMailer doesn't actually
 represent a separate request per se, that the request object is not
 being created correctly. Thus, when it goes to create the email using
 the template, it doesn't really know what format to use. Just a hunch.

 I'm kind of a Rails newb, so any help with this issue would be greatly
 appreciated. Just let me know if you need to know any other  
 information.

 Michael


 

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To post to this group, send email to rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~--~~~~--~~--~--~---



[Rails] serialize ... what am I doing wrong?

2009-02-14 Thread phil

Hi.
I want to serialize out an object to the database. But I am getting an
integer value in the column when I expect to see some yaml!

migration:
class CreateSummaries  ActiveRecord::Migration
  def self.up
create_table :summaries do |t|
   t.text :summary_data
  t.timestamps
end
  end
end

class:
class Summary  ActiveRecord::Base
  serialize :summary_data
end

example:
summary = Summary.new(:summary_data = User.first)
= #Summary id: nil, fss_player_id: nil, stats_type: nil, scope: nil,
summary_data: #User id: 4, login: LoginName, email: x...@xx.xx,
crypted_password: cbc8411974ad085f608b6e0a05dd608e7577de19, salt:
ddc4528beea65095b7f5619912a6ca0681d0c10e, created_at: 2008-09-12
18:43:19, updated_at: 2009-02-05 04:20:58, remember_token: nil,
remember_token_expires_at: nil, pw_reset_code: nil, role:
commissioner, sign_up_code:
44e11a23be5b7833bf73d479a05166c0e0377c56, reset_password_code_until:
nil, permalink: fname, name: FName, street: nil, city: nil,
province: nil, postcode: nil, country: nil, home_phone: nil,
mobile_phone: nil, display_name: FName, display_teams: true,
website: nil, occupation: nil, interests: nil, favourite_teams: nil,
anonymous_contact: false, created_at: nil, updated_at: nil
 summary.save!
= true
 Summary.first.summary_data
= 4

What am I doing wrong?

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To post to this group, send email to rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~--~~~~--~~--~--~---



[Rails] Re: Auto_complete plugin in Rails 2.2.2 (auto_complete_for method not found)

2009-02-14 Thread Spiros K.

Yes, the plugin IS in vendor plugins and YES you can check my first
post in the thread and see that my 2nd post was actually a typo in my
behalf. The problem remains as stated.

BTW, the code was copy-pasted from tutorials that supposedly work, so
I doubt there is any weird typo in the actual code.



On Feb 14, 12:41 pm, Frederick Cheung frederick.che...@gmail.com
wrote:
 On Feb 14, 9:58 am, Spiros K. spiros...@gmail.com wrote: Thanks for your 
 reply,
  but

  1. this specific plugin did not have an install.rb with it.
  2. 2.2.2 is as new as they get I just downloaded 3 weels ago...?! And
  i think it works just fine with git as I have downloaded from git as
  well (though it messed my tortoise svn structure pretty badly)

 so is the plugin in vendor/plugins ?

  Then fired up my script/server and still:

  method not found for autocomplete_for method!!! :-(

 I also assume that that was a typo and you actually write
 auto_complete_for in your controller.

 Fred





  On Feb 13, 12:55 pm, Frederick Cheung frederick.che...@gmail.com
  wrote:

   On 13 Feb 2009, at 09:19, Spiros K. wrote:

page not found error

* Trying to manually copy the files in the vendor/plugin directory of
my project (got them from the model_auto_completer example), but still
does not work... (if i execute script/plugin list there is nothing)

Regarding this last part, i have been trying to find documentation
about how to manually install a plugin, but with no results. In every
forum that someone asks how to do it manually people respond with
script/plugin install. This is automatic, not manually, as i am sure
most of you know. What i am searching for is instructions on: where to
place the files myself and what to execute myself so that my project
will 'use' the plugin.

   Copying the files into vendor/plugins is all there is to it 99% of the  
   time. Some plugins have an install.rb file that needs to be run after  
   this.
   Don't worry about the output of script/plugin list (which as far as I  
   can tell is for listing available, not installed plugins)

   The autocomplete plugin is on github these 
   days:http://github.com/rails/auto_complete/tree/master

   Newer versions of rails include a version of script/plugin that can  
   install plugins from git repositories (assuming you have git itself of  
   course).

   Fred

I will be thankful for any help you might offer, no matter how small,
but PLEASE don't repeat to me steps i have already taken with no
differentation what-so-ever. This is both pointless and insulting.

Yours sincerely,
a frustrated RoR programmer
Spiros K.- Hide quoted text -

 - Show quoted text -
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To post to this group, send email to rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~--~~~~--~~--~--~---



[Rails] Re: how can I secure rails script?

2009-02-14 Thread Lukey Portiski

Bpx Bpx wrote:
 Hello,
 I was searching for some way to secure my rails scripts. Do anybody know
 what can I use? I found Rencoder (www.rencoder.com) on the net but I
 want to know if there are others programs I can use?

Well, definitely don't use this Rencoder. Its not secure and frankly it 
failed to work on much Ruby code.  I tried it on the test.rb script and 
it does not work. It did work on print test though lol so if you're 
app is that basic maybe its ok.  I would avoid it
-- 
Posted via http://www.ruby-forum.com/.

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To post to this group, send email to rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~--~~~~--~~--~--~---



[Rails] Re: Schedule job in rails

2009-02-14 Thread Harold A . Giménez Ch .
No quite like that. If you're sending an HTTP GET request to any URL, you
would pass parameters to the URL itself, something like:
http://localhost:3000/cron?param1=value1param2=value2 etc

What looks attractive to me about this approach (of using wget via cron
instead of a rake task) is that you are not bringing up an entire rails
environment to handle a task. There's less overhead. Just be sure to lock it
down with a combination of things that have been suggested here: IP Address
check, local_request?, http basic authentication. There may be more you can
do...

On Sat, Feb 14, 2009 at 12:52 AM, Valentino Lun 
rails-mailing-l...@andreas-s.net wrote:


   wget http://localhost:3000/cron
 
  cron_controller invokes your method
 
  Thanks, it is a very good idea. How about if my action require 2
  parameters? How to do that?

 Let me further elabroate on my question. For example in my Cron
 Controller

 def someaction
   some_method(params[:one],params[:two])
 end

 Is it possible to do this in my crontab as follow?

 10 10 * * * wget http://localhost:3000/cron/someaction para1 para2

 Many thanks

 Valentino
 --
 Posted via http://www.ruby-forum.com/.

 


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To post to this group, send email to rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~--~~~~--~~--~--~---



[Rails] Re: Auto_complete plugin in Rails 2.2.2 (auto_complete_for method not found)

2009-02-14 Thread Frederick Cheung



On Feb 14, 3:52 pm, Spiros K. spiros...@gmail.com wrote:
 Yes, the plugin IS in vendor plugins and YES you can check my first
 post in the thread and see that my 2nd post was actually a typo in my
 behalf. The problem remains as stated.

odd. i'd stick a breakpoint in the plugin's init.rb to see what was
happening there (you should have vendor/plugins/auto_complete/init.rb
and vendor/plugins/auto_complete/lib ) If you have changed
config.plugins or config.plugin_paths in environment.rb that could
cause this (but I rather suspect you'd remember if you'd done that).

 BTW, the code was copy-pasted from tutorials that supposedly work, so
 I doubt there is any weird typo in the actual code.

I wouldn't be so sure :-)

Fred



 On Feb 14, 12:41 pm, Frederick Cheung frederick.che...@gmail.com
 wrote:

  On Feb 14, 9:58 am, Spiros K. spiros...@gmail.com wrote: Thanks for 
  your reply,
   but

   1. this specific plugin did not have an install.rb with it.
   2. 2.2.2 is as new as they get I just downloaded 3 weels ago...?! And
   i think it works just fine with git as I have downloaded from git as
   well (though it messed my tortoise svn structure pretty badly)

  so is the plugin in vendor/plugins ?

   Then fired up my script/server and still:

   method not found for autocomplete_for method!!! :-(

  I also assume that that was a typo and you actually write
  auto_complete_for in your controller.

  Fred

   On Feb 13, 12:55 pm, Frederick Cheung frederick.che...@gmail.com
   wrote:

On 13 Feb 2009, at 09:19, Spiros K. wrote:

 page not found error

 * Trying to manually copy the files in the vendor/plugin directory of
 my project (got them from the model_auto_completer example), but still
 does not work... (if i execute script/plugin list there is nothing)

 Regarding this last part, i have been trying to find documentation
 about how to manually install a plugin, but with no results. In every
 forum that someone asks how to do it manually people respond with
 script/plugin install. This is automatic, not manually, as i am sure
 most of you know. What i am searching for is instructions on: where to
 place the files myself and what to execute myself so that my project
 will 'use' the plugin.

Copying the files into vendor/plugins is all there is to it 99% of the  
time. Some plugins have an install.rb file that needs to be run after  
this.
Don't worry about the output of script/plugin list (which as far as I  
can tell is for listing available, not installed plugins)

The autocomplete plugin is on github these 
days:http://github.com/rails/auto_complete/tree/master

Newer versions of rails include a version of script/plugin that can  
install plugins from git repositories (assuming you have git itself of  
course).

Fred

 I will be thankful for any help you might offer, no matter how small,
 but PLEASE don't repeat to me steps i have already taken with no
 differentation what-so-ever. This is both pointless and insulting.

 Yours sincerely,
 a frustrated RoR programmer
 Spiros K.- Hide quoted text -

  - Show quoted text -
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To post to this group, send email to rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~--~~~~--~~--~--~---



[Rails] SUCCESS!! BUG?? Re: 2 button_to functions for file downloads

2009-02-14 Thread Me

OK Well this must be a bug I guess but I managed to get it to work.

For some reason the first one was trying to give the js response to
the action.  So for the hey of it I used 3 button_to's and the bottom
two worked while the first one was giving me the same response.

div style=display: none;%= button_to 'Download PCCIS file',
:action = 'downloadpccis' %/div
%= button_to 'Download PCCIS file',:action = 'downloadcis' %
%= button_to 'Download PCCIS file',:action = 'downloadpccis' %


On Feb 13, 6:22 pm, Me chabg...@gmail.com wrote:
 Anyone have any ideas why the second button works but the first button
 is giving me the above error?

 On Feb 12, 10:27 pm, Me chabg...@gmail.com wrote:

  For some reason the first button is giving me this for a response:
  try {
  $(notification).update(h1 style='display: inline' class='mes'Site
  123 was built/h1);
  $(downloads).show();} catch (e) { alert('RJS error:\n\n' + e.toString()); 
  alert('$

  (\notification\).update(\h1 style=\'display: inline\' class=\'mes
  \'Site 123 was built/h1\);\n$(\downloads\).show();'); throw e }

  On Feb 12, 9:45 pm, Chris Habgood chabg...@gmail.com wrote:

   Application.rhtml:
   % form_tag( {:action = 'mltn6p'}  ) do -%
   div id=page
       div id=header
           h1Wendia Site entry Program/h1
       /div
       div id=menu
           fieldset
               legendSelect your Shelf/legend
               %= select(:node, :id, $shelves,{:prompt ='Select 
   Equipment'},{
   :onchange = remote_function(:url = { :action = gotoshelf})} ) %
           /fieldsetbr /
           %= render :partial = 'sitedata' %
           fieldset id=downloads style=display: none
               legendDownload POB Files/legend
               %=button_to'Download CISfile',         :action =
   'downloadcis' %
               %=button_to'Download PCCISfile',     :action =
   'downloadpccis' %
           /fieldset
       /div

       div id=content
           div id=notification /div
               %= yield %
       /div
   /div
   % end %

   controller:
   def downloadcis
           send_file(#{$site.upcase}_CIS.csv, :type = 'text/plain',
   :disposition = 'attachment')
     end

       def downloadpccis
           send_file(#{$site.upcase}_PCCIS.csv, :type = 'text/plain',
   :disposition = 'attachment')
       end

   On Thu, Feb 12, 2009 at 9:24 PM, bill walton bwalton...@gmail.com wrote:

On Thu, 2009-02-12 at 17:29 -0800, Me wrote:
 Anyone have any idea why one button does a submit and
 the other does afiledownload?

In general, element behavior in any page is a function of the browser
parser's ability to make sense of the code we feed it.  Post your code
and we might be able to help.

Best regards,
Bill


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To post to this group, send email to rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~--~~~~--~~--~--~---



[Rails] Re: SUCCESS!! BUG?? Re: 2 button_to functions for file downloads

2009-02-14 Thread Frederick Cheung



On Feb 14, 5:54 pm, Me chabg...@gmail.com wrote:
 OK Well this must be a bug I guess but I managed to get it to work.

button_to generates a form for you with a button. You've put a button
in a form, therefore in the generated html there will be a form nested
inside a form which isn't valid html (and also sorts of weird stuff
can happen, like the wrong form being generated).

Fred

 For some reason the first one was trying to give the js response to
 the action.  So for the hey of it I used 3 button_to's and the bottom
 two worked while the first one was giving me the same response.

 div style=display: none;%= button_to 'Download PCCIS file',
         :action = 'downloadpccis' %/div
 %= button_to 'Download PCCIS file',         :action = 'downloadcis' %
 %= button_to 'Download PCCIS file',         :action = 'downloadpccis' %

 On Feb 13, 6:22 pm, Me chabg...@gmail.com wrote:

  Anyone have any ideas why the second button works but the first button
  is giving me the above error?

  On Feb 12, 10:27 pm, Me chabg...@gmail.com wrote:

   For some reason the first button is giving me this for a response:
   try {
   $(notification).update(h1 style='display: inline' class='mes'Site
   123 was built/h1);
   $(downloads).show();} catch (e) { alert('RJS error:\n\n' + 
   e.toString()); alert('$

   (\notification\).update(\h1 style=\'display: inline\' class=\'mes
   \'Site 123 was built/h1\);\n$(\downloads\).show();'); throw e }

   On Feb 12, 9:45 pm, Chris Habgood chabg...@gmail.com wrote:

Application.rhtml:
% form_tag( {:action = 'mltn6p'}  ) do -%
div id=page
    div id=header
        h1Wendia Site entry Program/h1
    /div
    div id=menu
        fieldset
            legendSelect your Shelf/legend
            %= select(:node, :id, $shelves,{:prompt ='Select 
Equipment'},{
:onchange = remote_function(:url = { :action = gotoshelf})} ) %
        /fieldsetbr /
        %= render :partial = 'sitedata' %
        fieldset id=downloads style=display: none
            legendDownload POB Files/legend
            %=button_to'Download CISfile',         :action =
'downloadcis' %
            %=button_to'Download PCCISfile',     :action =
'downloadpccis' %
        /fieldset
    /div

    div id=content
        div id=notification /div
            %= yield %
    /div
/div
% end %

controller:
def downloadcis
        send_file(#{$site.upcase}_CIS.csv, :type = 'text/plain',
:disposition = 'attachment')
  end

    def downloadpccis
        send_file(#{$site.upcase}_PCCIS.csv, :type = 'text/plain',
:disposition = 'attachment')
    end

On Thu, Feb 12, 2009 at 9:24 PM, bill walton bwalton...@gmail.com 
wrote:

 On Thu, 2009-02-12 at 17:29 -0800, Me wrote:
  Anyone have any idea why one button does a submit and
  the other does afiledownload?

 In general, element behavior in any page is a function of the browser
 parser's ability to make sense of the code we feed it.  Post your code
 and we might be able to help.

 Best regards,
 Bill
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To post to this group, send email to rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~--~~~~--~~--~--~---



[Rails] Re: restful_authentication with rails 2.2

2009-02-14 Thread Sandeep Sagar
I have recently setup restful_auth.. on 2.2.2  and all the unit tests passed
except for a little correction in the users.yml (fixture)

I have been able to successfully create and activate users.

I did setup with acts_as_state_machine (AASM) too.

 

Some things I would check-

Did the migration from 2.1 to 2.2 succeed?

Are the unit tests successful?

 

Hope this helps.

-Master Chief

(RoR noob)

  _  

From: rubyonrails-talk@googlegroups.com
[mailto:rubyonrails-t...@googlegroups.com] On Behalf Of Rodrigo Muiño
Sent: Friday, February 13, 2009 9:36 AM
To: rubyonrails-talk@googlegroups.com
Subject: [Rails] restful_authentication with rails 2.2

 

Guys, I am using restful_authentication with rails 2.2 an realized that when
a user tries to sign up the activation code that is set to his email is
different from the one in the database.
Do you know if this is an issue of rails 2.2?
It used to work fine withe rails 2.1


Thanks
Rodrigo



--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To post to this group, send email to rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~--~~~~--~~--~--~---



[Rails] What is the difference between build and new

2009-02-14 Thread John Smith

I use new in almost all my controllers, but sometimes I have seen the
build method inside the controllers of some apps. Can someone explain
when should I use build?
-- 
Posted via http://www.ruby-forum.com/.

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To post to this group, send email to rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~--~~~~--~~--~--~---



[Rails] Re: What is the difference between build and new

2009-02-14 Thread Phlip

John Smith wrote:

 I use new in almost all my controllers, but sometimes I have seen the
 build method inside the controllers of some apps. Can someone explain
 when should I use build?

.build fixes the fact you cannot say this:

   my_post.tags.new(:name = 'reggae')

The new() operator is special, and your editor might color it different. So the 
architects of ActiveRecord use .build() instead.

Both create a new object. But shouldn't we just use this?

   my_post.tags.create(:name = 'reggae')
   my_post.tags.create!(:name = 'reggae')

What do they do?

-- 
   Phlip


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To post to this group, send email to rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~--~~~~--~~--~--~---



[Rails] Re: can't find gems in /vendor/gems/ after modifying load_paths

2009-02-14 Thread Matt Jones



On Feb 13, 11:42 am, Sarah Allen rails-mailing-l...@andreas-s.net
wrote:
 I'm picking up a Rails app that is using a lot of older gems.  We're
 using Rails 2.0.2 and planning to move to to Rails 2.3 along with
 upgrading the the dependencies.  However, in the meantime, we're moving
 servers around and adding new folks to the dev team, so I thought it
 wise to freeze the gems.  I'm trying to follow the methodology
 described here:http://errtheblog.com/posts/50-vendor-everything
 and here:http://wiki.joyent.com/shared:kb:installing-rails

 Unfortunately, the gems don't seem to be found.

 Here's what I did... I had all the old gems installed to ~/.gems and all
 the tests passed.  Then I unpacked the gems into /vendor/gems

 cd ~/rails/vendor/gems
 gem unpack exifr
 gem unpack rmagick
 gem unpack tzinfo
 gem unpack uuidtools

 I added the following to config/enviroment.rb inside
 Rails::Initializer.run do |config|

 config.load_paths += Dir[#{RAILS_ROOT}/vendor/gems/**].map do |dir|
   File.directory?(lib = #{dir}/lib) ? lib : dir
 end
 # print out my load_paths for debugging
 config.load_paths.each do |p|
   puts p
 end

 and later:
 require 'rubygems'
 gem 'exifr', '=0.10.6'
 gem 'uidtools', '=1.0.2'
 gem 'rmagick', '=1.15.8'
 gem 'tzinfo', '=0.3.5'



Take a careful look at the errtheblog article - you should be using
require, not gem here.
The gem statements only add the gem directories to the load_path.

In the long run, you should definitely switch over to using
config.gem, but that isn't an
option with Rails 2.0.3.

BTW, even changing to 'require's is still going to leave you with
problems, as RMagick's
native component hasn't been built yet. I don't know of any easy way
to do it in your
situation. You might want, for the short term, to just leave the 'gem'
lines in your environment
and keep the gem packages for the gems you need around. That way, the
code will complain
loudly if the gems needed aren't installed.

--Matt Jones


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To post to this group, send email to rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~--~~~~--~~--~--~---



[Rails] Re: serialize ... what am I doing wrong?

2009-02-14 Thread Rick

Summary.new is expecting to receive a hash, which isn't what you're
giving it.

i.e.:
summary = Summary.new( :summary_data = { name=Administator,
login=admin } )

summary.save!

Summary.last.summary_data
= {name=Administrator, login=admin}

On Feb 14, 5:29 am, phil p...@philsmy.com wrote:
 Hi.
 I want to serialize out an object to the database. But I am getting an
 integer value in the column when I expect to see some yaml!

 migration:
 class CreateSummaries  ActiveRecord::Migration
   def self.up
     create_table :summaries do |t|
        t.text :summary_data
       t.timestamps
     end
   end
 end

 class:
 class Summary  ActiveRecord::Base
   serialize :summary_data
 end

 example:
 summary = Summary.new(:summary_data = User.first)
 = #Summary id: nil, fss_player_id: nil, stats_type: nil, scope: nil,
 summary_data: #User id: 4, login: LoginName, email: x...@xx.xx,
 crypted_password: cbc8411974ad085f608b6e0a05dd608e7577de19, salt:
 ddc4528beea65095b7f5619912a6ca0681d0c10e, created_at: 2008-09-12
 18:43:19, updated_at: 2009-02-05 04:20:58, remember_token: nil,
 remember_token_expires_at: nil, pw_reset_code: nil, role:
 commissioner, sign_up_code:
 44e11a23be5b7833bf73d479a05166c0e0377c56, reset_password_code_until:
 nil, permalink: fname, name: FName, street: nil, city: nil,
 province: nil, postcode: nil, country: nil, home_phone: nil,
 mobile_phone: nil, display_name: FName, display_teams: true,
 website: nil, occupation: nil, interests: nil, favourite_teams: nil,
 anonymous_contact: false, created_at: nil, updated_at: nil summary.save!
 = true
  Summary.first.summary_data

 = 4

 What am I doing wrong?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To post to this group, send email to rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~--~~~~--~~--~--~---



[Rails] Re: What is the difference between build and new

2009-02-14 Thread Rob Biedenharn

On Feb 14, 2009, at 2:37 PM, Phlip wrote:
 John Smith wrote:

 I use new in almost all my controllers, but sometimes I have seen the
 build method inside the controllers of some apps. Can someone explain
 when should I use build?

 .build fixes the fact you cannot say this:

   my_post.tags.new(:name = 'reggae')

 The new() operator is special, and your editor might color it  
 different. So the
 architects of ActiveRecord use .build() instead.

 Both create a new object. But shouldn't we just use this?

   my_post.tags.create(:name = 'reggae')
   my_post.tags.create!(:name = 'reggae')

 What do they do?

 -- 
   Phlip


In particular, #build (and #create) automatically set, in this case,  
the :post_id of the associated Tag object to be my_post.id

There are times when you want to work briefly with an unsaved object  
and #build is more appropriate than #create

-Rob

Rob Biedenharn  http://agileconsultingllc.com
r...@agileconsultingllc.com

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To post to this group, send email to rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~--~~~~--~~--~--~---



[Rails] Re: reaper is not picking up new changes to my application???

2009-02-14 Thread Greg Hauptmann
(bump) still really keen if someone has any info on this one (see below)

2009/2/10 Greg Hauptmann greg.hauptmann.r...@gmail.com

 Still stuck on this.  I made sure I wasn't in the current directory when
 I did the call to reaper and I still get the same result, i.e. whilst the
 process restarts it does not restart with the latest application updates
 (made available via the new application being put in a new releases
 directory, and then capistrano change the sym link for current to this new
 directory).

 Question - Is a reaper restart action supposed to update an application?
   That is, is the out-of-the box Capistrano command
 /u/apps/equity/current/script/process/reaper really supposed to update any
 changes to an application (via a cap deploy)?


 *** BEFORE CALLING REAPER 
 [r...@home equity]# ps ax | grep -i ruby
 12857 ?S  0:02 ruby
 /usr/local/lib/ruby/gems/1.8/gems/mongrel-1.1.5/bin/mongrel_rails start -d
 -a 0.0.0.0 -p 3001 -P 
 /u/apps/equity/releases/20090209112325/tmp/pids/dispatch.3001.pid
 -e production -c /u/apps/equity/releases/20090209112325 -l
 /u/apps/equity/releases/20090209112325/log/mongrel.log
 13036 pts/1R+ 0:00 grep -i ruby
 [r...@home equity]# cat current/tmp/pids/dispatch.3001.pid
 12857[r...@home equity]# ls -l
 total 2
 lrwxrwxrwx   1 root root   38 Feb 10 21:10 current -
 /u/apps/equity/releases/20090210111005
 drwxrwxr-x  24 root root 1024 Feb 10 21:10 releases
 drwxrwxr-x   6 root root 1024 Feb  8 20:46 shared

 *** CALL REAPER ***
 [r...@home equity]# /u/apps/equity/current/script/process/reaper
 Restarting 12857


 *** AFTER CALLING REAPER ***
 [r...@home equity]# ps ax | grep -i ruby
 13043 ?S  0:02 ruby
 /usr/local/lib/ruby/gems/1.8/gems/mongrel-1.1.5/bin/mongrel_rails start -d
 -a 0.0.0.0 -p 3001 -P 
 /u/apps/equity/releases/20090209112325/tmp/pids/dispatch.3001.pid
 -e production -c /u/apps/equity/releases/20090209112325 -l
 /u/apps/equity/releases/20090209112325/log/mongrel.log
 13048 pts/1R+ 0:00 grep -i ruby
 [r...@home equity]# ls -l
 total 2
 lrwxrwxrwx   1 root root   38 Feb 10 21:10 current -
 /u/apps/equity/releases/20090210111005
 drwxrwxr-x  24 root root 1024 Feb 10 21:10 releases
 drwxrwxr-x   6 root root 1024 Feb  8 20:46 shared
 [r...@home equity]# cat current/tmp/pids/dispatch.3001.pid
 13043[r...@home equity]#
 [r...@home equity]#


 Regards
 Greg


 2009/2/9 Greg Hauptmann greg.hauptmann.r...@gmail.com

 I think I see what you're getting at - this is actually the result of
 running the out of the box capistrano script - here's the cap deploy output
 for example (I just wanted to make it simpler re my post)
 Macintosh-2:equity greg$ cap deploy -n
   * executing `deploy'
   * executing `deploy:update'
  ** transaction: start
   * executing `deploy:update_code'
 updating the cached checkout on all servers
 executing locally: git ls-remote /Users/greg/source/equity/.git HEAD
   * executing if [ -d /u/apps/equity/shared/cached-copy ]; then cd
 /u/apps/equity/shared/cached-copy  git fetch -q origin  git reset -q
 --hard 43f8b3df4d8f1f6358b803fbb41f38fcb1a9ddc4; else git clone -q
 g...@10.1.1.102:/Users/greg/source/equity/.git
 /u/apps/equity/shared/cached-copy  cd /u/apps/equity/shared/cached-copy 
 git checkout -q -b deploy 43f8b3df4d8f1f6358b803fbb41f38fcb1a9ddc4; fi
 copying the cached version to /u/apps/equity/releases/20090209085535
   * executing cp -RPp /u/apps/equity/shared/cached-copy
 /u/apps/equity/releases/20090209085535  (echo
 43f8b3df4d8f1f6358b803fbb41f38fcb1a9ddc4 
 /u/apps/equity/releases/20090209085535/REVISION)
   * executing `deploy:finalize_update'
   * executing chmod -R g+w /u/apps/equity/releases/20090209085535
   * executing rm -rf /u/apps/equity/releases/20090209085535/log
 /u/apps/equity/releases/20090209085535/public/system
 /u/apps/equity/releases/20090209085535/tmp/pids \\\n  mkdir -p
 /u/apps/equity/releases/20090209085535/public \\\n  mkdir -p
 /u/apps/equity/releases/20090209085535/tmp \\\n  ln -s
 /u/apps/equity/shared/log /u/apps/equity/releases/20090209085535/log \\\n
  ln -s /u/apps/equity/shared/system
 /u/apps/equity/releases/20090209085535/public/system \\\n  ln -s
 /u/apps/equity/shared/pids /u/apps/equity/releases/20090209085535/tmp/pids
   * executing find /u/apps/equity/releases/20090209085535/public/images
 /u/apps/equity/releases/20090209085535/public/stylesheets
 /u/apps/equity/releases/20090209085535/public/javascripts -exec touch -t
 200902090855.35 {} ';'; true
   * executing `deploy:symlink'
   * executing rm -f /u/apps/equity/current  ln -s
 /u/apps/equity/releases/20090209085535 /u/apps/equity/current
  ** transaction: commit
   * executing `deploy:restart'
   * executing /u/apps/equity/current/script/process/reaper
 Macintosh-2:equity greg$



 2009/2/9 MaD mayer.domi...@gmail.com


 i really don't know about reaper (as i'm not using it), but i guess
 your problem is with the symlink current. you are calling reaper
 from that 

[Rails] Re: can't find gems in /vendor/gems/ after modifying load_paths

2009-02-14 Thread Sarah Allen

Matt Jones wrote:
 Take a careful look at the errtheblog article - you should be using
 require, not gem here.
 The gem statements only add the gem directories to the load_path.

Changing to 'require' got past that error.  I still don't understand why 
it failed to load since I had requires elsewhere that just didn't 
specify the version.  Where would I look up the syntax reference for 
'gem' and 'require' ?  I'm not really clear where those come from.  I 
see 'require' documented here: http://www.rubygems.org/read/chapter/3
but it doesn't reference the version argument and I don't see where 
'gem' is documented.

 In the long run, you should definitely switch over to using
 config.gem, but that isn't an
 option with Rails 2.0.3.
I'll give that a look when we upgrade.

 BTW, even changing to 'require's is still going to leave you with
 problems, as RMagick's
 native component hasn't been built yet. I don't know of any easy way
 to do it in your
 situation. 
Thanks for the warning.

 You might want, for the short term, to just leave the 'gem'
 lines in your environment
 and keep the gem packages for the gems you need around. That way, the
 code will complain
 loudly if the gems needed aren't installed.
Hmmm... so it seems that 'gem' just declares that the code depends on a 
gem, and 'require' actually loads the library?

Thanks so much!
Sarah
-- 
Posted via http://www.ruby-forum.com/.

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To post to this group, send email to rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~--~~~~--~~--~--~---



[Rails] Re: cPanel Ruby Gems

2009-02-14 Thread Matt Jones



On Feb 13, 9:49 am, Rob Pa rails-mailing-l...@andreas-s.net wrote:
 Michael Mike wrote:
  Did you find a solution to this? I am experiencing the same problem.

 I contacted my host and got them to update my Ruby Gems.

 However I now get this message;

 :0:Warning: Gem::SourceIndex#search support for Regexp patterns is
 deprecated


That's odd... what command produces that warning? Something is calling
Gem.source_index.search(/some_regexp/, ...) when it shouldn't.

--Matt Jones


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To post to this group, send email to rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~--~~~~--~~--~--~---



[Rails] Two-to-one mappings

2009-02-14 Thread Greg Brockman

Hey all,

I have a pretty simple question, but I'm not sure of a good solution
to it.  Essentially, I want to provide a two-to-one mapping of models.
 I'm working on an application for a contest, where every (unordered)
combination of two Rounds is supposed to be assigned to one Room.  Any
Room might have many different combinations of Rounds, however.

What is the Right Way of doing this in Rails?  Maybe create a model
that holds the associated foreign keys?  Also, what would be a good
way to scale this out, if I wanted to be able to map unordered
n-element collections of Rounds to obtain a Room?

Thanks,

Greg

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To post to this group, send email to rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~--~~~~--~~--~--~---



[Rails] Re: What is the difference between build and new

2009-02-14 Thread DarkTatka

build does not save the object. create does. if saving fails, create
returns false, create! raises error (useful in migration, will
rollback)

On 14 Ún, 20:37, Phlip phlip2...@gmail.com wrote:
 John Smith wrote:
  I use new in almost all my controllers, but sometimes I have seen the
  build method inside the controllers of some apps. Can someone explain
  when should I use build?

 .build fixes the fact you cannot say this:

    my_post.tags.new(:name = 'reggae')

 The new() operator is special, and your editor might color it different. So 
 the
 architects of ActiveRecord use .build() instead.

 Both create a new object. But shouldn't we just use this?

    my_post.tags.create(:name = 'reggae')
    my_post.tags.create!(:name = 'reggae')

 What do they do?

 --
    Phlip
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To post to this group, send email to rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~--~~~~--~~--~--~---



[Rails] Re: can this be done without using find_by_sql

2009-02-14 Thread DarkTatka

named scope is definitely the way to go. check out
http://guides.rubyonrails.org/active_record_querying.html#_named_scopes
for more options (especialy named scope with argument)

On 14 Ún, 13:32, tonypm tonypmar...@hotmail.com wrote:
 Just to finish the story.

 Sorry -  the distinct in the select is needed, I missed it out.

 Going a step further, I now have:

 named_scope :flagged_repairs, :select = 'distinct repairs.*', :joins
 = :repair_notes, :conditions = [notes.flagged = ?, true]

 So in my search, where I am building a dynamic scope (thanks to
 railscasts)
 I can do:

 scope.flagged_repairs.paginate(:page=page, :per_page=per_page)

 And it all appears to work!!

 Incredibly neat

 Tonypm
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To post to this group, send email to rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~--~~~~--~~--~--~---



[Rails] Re: gem cleanup and rails 1.2.6 problem

2009-02-14 Thread Charles Johnson
The problem is with your path. You want /System/Library...
but you are doing -/System/Library...

See the difference?

Cheers--

Charles

On Fri, Feb 13, 2009 at 3:35 PM, elle wazne...@gmail.com wrote:


 gem list -d rails gives me:

 *** LOCAL GEMS ***

 rails (2.2.2, 1.2.6)
Author: David Heinemeier Hansson
Rubyforge: http://rubyforge.org/projects/rails
Homepage: http://www.rubyonrails.org
Installed at (2.2.2): /Library/Ruby/Gems/1.8
 (1.2.6): /System/Library/Frameworks/Ruby.framework/
 Versions/1.8/usr/lib/ruby/gems/1.8

 Web-application framework with template engine, control-flow
 layer,
and ORM.

 Then running:
 sudo gem uninstall --install-dir -/System/Library/Frameworks/
 Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8 rails
 gives me:

 ERROR:  While executing gem ... (Gem::InstallError)
Unknown gem rails = 0



 Elle



 On Feb 14, 8:19 am, Charles Johnson gm.johns...@gmail.com wrote:
  On Fri, Feb 13, 2009 at 2:43 PM, elle wazne...@gmail.com wrote:
 
   Running it with sudo I get:
 
   ERROR:  While executing gem ... (Gem::InstallError)
   Unknown gem rails = 0
 
   Do I need to actually sign in as root?
 
   Cheers,
   Elle
 
  You should be OK with sudo. Can you post your *exact* command line, and
 the
  output from gem list -d rails
 
  HTH
 
  Charles
 


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To post to this group, send email to rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~--~~~~--~~--~--~---



[Rails] Re: association include and joins issues - 'Unknown Column' error

2009-02-14 Thread Chris Warren

Excellent! Thanks for the clarification, Fred! I think adding the
trait_values as an inner join will do the trick.

  -Chris


On Sat, Feb 14, 2009 at 5:26 AM, Frederick Cheung
frederick.che...@gmail.com wrote:



 On Feb 14, 12:43 am, Chris csw11...@gmail.com wrote:
 Hi all,

 I'd really appreciate any help / advice on this problem. When I test
 this

   def edit
 @entity = Entity.find(params[:id],
   :include = :key_factors)
 @traits = Trait.find :all,
  :include = :trait_values,
  :joins = :trait_values,
  :joins = LEFT OUTER JOIN key_factors ON
 key_factors.trait_value_id = trait_values.id AND
 key_factors.entity_id=+...@entity.id.to_s,
  :order = 'traits.ordering, traits.name'
 @frequencies = Frequency.find :all,
   :order = 'value'
   end

 I get the error ActiveRecord::StatementInvalid: Mysql::Error: Unknown
 column 'trait_values.id' in 'on clause': SELECT `traits`.* FROM
 `traits`  LEFT OUTER JOIN key_factors ON key_factors.trait_value_id =
 trait_values.id AND key_factors.entity_id=953125641. I would have
 thought that since I'm including trait_values then that table would be
 in the SQL statement. However, what I see in the development log is:

   [4;36 Entity Load (0.0ms)   SELECT * FROM `entities` WHERE
 (`entities`.`id` = 1)
   [4;35 KeyFactor Load (0.0ms) SELECT `key_factors`.* FROM
 `key_factors` WHERE (`key_factors`.entity_id = 1)
   [4;36 Trait Load (0.0ms)Mysql::Error: Unknown column
 'trait_values.id' in 'on clause': SELECT `traits`.* FROM `traits` LEFT
 OUTER JOIN key_factors ON key_factors.trait_value_id = trait_values.id
 AND key_factors.entity_id=1 ORDER BY traits.ordering, traits.name

 Which suggests that Rails is doing a separate call for each include...
 and a bit of research on the API confirms that. However, in an earlier
 version of rails this worked fine - the log for running the exact same
 code shows (more or less - replaced a long field list with '*' to make
 reading easier)

 Yup that is what happens. It should fall back to the old code in cases
 like this however I suspect that it doesn't check the :joins clause
 for tables for that need to be included in the old way.
 I'm assuming you do actually want that include (and that it wasn't
 just an easy way of triggering a join) since the answer is probably a
 lot easier if you don't need the include.
 Rails will fall back to the old code whenever it sees something that
 looks like you're using a table that isn't the base table or provided
 through the joins clause. As I said, unfortunately I don't think it
 checks the join clause in this way for references to tables.

 You should be able fix it by adding a dud condition that references
 the included table. I suspect it was just you poking around but doing

 :joins = :trait_values,
 :joins = LEFT OUTER JOIN key_factors ON  ... 

 doesn't do anything since a hash  can only have one value for a given
 key.
 YOu could also try

 :joins = INNER JOIN trait_values ON ... LEFT OUTER JOIN key_factors
 ON  ... 

 This would allow the query to run ok, however I suspect it would still
 process the include off the back of a second query.

 Fred

   [4;36 Trait Load Including Associations (0.00) SELECT * FROM
 traits LEFT OUTER JOIN trait_values ON trait_values.trait_id =
 traits.id LEFT OUTER JOIN key_factors ON key_factors.trait_value_id =
 trait_values.id AND key_factors.entity_id=1 ORDER BY traits.ordering,
 traits.name

 My models are:

 class Trait  ActiveRecord::Base
   has_many :trait_values, :dependent = :destroy
 end

 class TraitValue  ActiveRecord::Base
   belongs_to :trait
   has_many :key_factors, :dependent = :destroy
   has_many :trait_value_images, :foreign_key =
 'related_id', :dependent = :destroy

   def sorter
 [(self.trait.ordering || 0),(self.trait.name || 0),
 (self.ordering || 0),(self.name || )]
   end

 end

 The API suggests that having conditions on a has_many association
 might do the trick, but the condition would be to be able to be
 dynamically specified (...key_factors.entity_id=+...@entity.id.to_s)
 and I don't see how that's possible when defining the condition on the
 association in the model (not sure whether that's because it actually
 isn't possible or just because I don't know Rails well enough).

 Please help!

   -Chris Warren
 


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To post to this group, send email to rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~--~~~~--~~--~--~---



[Rails] Trying the ol' articles route, need some help

2009-02-14 Thread yaphi

Hey there,

I am trying to figure out routing and thought that this would probably
be the best way to learn how to do some complicated routes. I've
looked at a lot of people's methods for getting the /articles/
2009/02/12/some-title to work but they all seem to forget to post some
custom method they're writing like by_date.

So here was my stab at it, I know I need to gsub the title. I just
don't know where (in the conditions?)

code
// routes.rb
map.article_page 'articles/:year/:month/:title', :controller =
'articles', :action = show,
:requirements = { :year = /(19|20)\d\d/, :month = /[01]?\d/ }

// articles_controller.rb
def show
@article = Article.find_by_date(params)
...

// article.rb
def self.find_by_date(params)
find(:first, :conditions = [publish_date.year = ? and
publish_date.month = ? and title = ?, params[:year], params[:month],
params[:title]])
  end
/code

I know publish_date.year is wrong but I can't figure out a way to pull
the year out of the publish_date column here.

Any help would be surely appreciated.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To post to this group, send email to rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~--~~~~--~~--~--~---



[Rails] Execute cap deploy:migrations fails

2009-02-14 Thread olivierntk

Hi there, I am trying to deploy a rails app on dreamhost.

Here is the error message that I get:

fatal: 'home/USER_NAME/DOMAIN_NAME/git/APPLICATION_NAME.git': unable
to chdir or not a git archive
fatal: The remote end hung up unexpectedly
/Users/USER/.gem/ruby/1.8/gems/capistrano-2.5.3/lib/capistrano/recipes/
deploy/scm/git.rb:224:in `query_revision': Unable to resolve revision
for 'master' on repository

I am using Capistrano v2.5.3, Rails 2.2 and Git v1.6

I ran deploy:setup and deploy:check successfully. I get the following
message when I run deploy:check command You appear to have all
necessary dependencies installed.

Here is my deploy script

default_run_options[:pty] = true

# be sure to change these
set :user, 'USER_NAME'
set :domain, 'DOMAIN_NAME'
set :application, 'APP_NAME'

# the rest should be good
set :repository,  #{us...@#{domain}:home/#{user}/#{domain}/git/#
{application}.git
set :deploy_to, /home/#{user}/#{domain}
set :deploy_via, :remote_cache
set :scm, 'git'
set :branch, 'master'
set :git_shallow_clone, 1
set :scm_verbose, true
set :use_sudo, false

server domain, :app, :web
role :db, domain, :primary = true

namespace :deploy do
  task :restart do
run touch #{current_path}/tmp/restart.txt
  end
end

I am guessing my path to my git repository is incorrect but I checked
many ... many times and this is my path on my host.

Any help would be greatly appreciated, thank you

Olivier


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To post to this group, send email to rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~--~~~~--~~--~--~---



[Rails] Re: Execute cap deploy:migrations fails

2009-02-14 Thread Maurício Linhares

Try to remove the set :deploy_via, :remote_cache, could never get it to work.

-
Maurício Linhares
http://alinhavado.wordpress.com/ (pt-br) | http://blog.codevader.com/ (en)



On Sat, Feb 14, 2009 at 10:51 PM, olivierntk olivier...@gmail.com wrote:

 Hi there, I am trying to deploy a rails app on dreamhost.

 Here is the error message that I get:

 fatal: 'home/USER_NAME/DOMAIN_NAME/git/APPLICATION_NAME.git': unable
 to chdir or not a git archive
 fatal: The remote end hung up unexpectedly
 /Users/USER/.gem/ruby/1.8/gems/capistrano-2.5.3/lib/capistrano/recipes/
 deploy/scm/git.rb:224:in `query_revision': Unable to resolve revision
 for 'master' on repository

 I am using Capistrano v2.5.3, Rails 2.2 and Git v1.6

 I ran deploy:setup and deploy:check successfully. I get the following
 message when I run deploy:check command You appear to have all
 necessary dependencies installed.

 Here is my deploy script

 default_run_options[:pty] = true

 # be sure to change these
 set :user, 'USER_NAME'
 set :domain, 'DOMAIN_NAME'
 set :application, 'APP_NAME'

 # the rest should be good
 set :repository,  #{us...@#{domain}:home/#{user}/#{domain}/git/#
 {application}.git
 set :deploy_to, /home/#{user}/#{domain}
 set :deploy_via, :remote_cache
 set :scm, 'git'
 set :branch, 'master'
 set :git_shallow_clone, 1
 set :scm_verbose, true
 set :use_sudo, false

 server domain, :app, :web
 role :db, domain, :primary = true

 namespace :deploy do
  task :restart do
run touch #{current_path}/tmp/restart.txt
  end
 end

 I am guessing my path to my git repository is incorrect but I checked
 many ... many times and this is my path on my host.

 Any help would be greatly appreciated, thank you

 Olivier


 


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To post to this group, send email to rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~--~~~~--~~--~--~---



[Rails] Re: Execute cap deploy:migrations fails

2009-02-14 Thread Freddy Andersen

Looking at the print from capistrano:

fatal: 'home/USER_NAME/DOMAIN_NAME/git/APPLICATION_NAME.git':
unable ???

That just does not look right.

From the host where you have capistrano are you able to run git clone
and the git url ?

Here is a git example url

set :repository, g...@github.com:username/projectname.git



On Feb 14, 5:51 pm, olivierntk olivier...@gmail.com wrote:
 Hi there, I am trying to deploy a rails app on dreamhost.

 Here is the error message that I get:

 fatal: 'home/USER_NAME/DOMAIN_NAME/git/APPLICATION_NAME.git': unable
 to chdir or not a git archive
 fatal: The remote end hung up unexpectedly
 /Users/USER/.gem/ruby/1.8/gems/capistrano-2.5.3/lib/capistrano/recipes/
 deploy/scm/git.rb:224:in `query_revision': Unable to resolve revision
 for 'master' on repository

 I am using Capistrano v2.5.3, Rails 2.2 and Git v1.6

 I ran deploy:setup and deploy:check successfully. I get the following
 message when I run deploy:check command You appear to have all
 necessary dependencies installed.

 Here is my deploy script

 default_run_options[:pty] = true

 # be sure to change these
 set :user, 'USER_NAME'
 set :domain, 'DOMAIN_NAME'
 set :application, 'APP_NAME'

 # the rest should be good
 set :repository,  #{us...@#{domain}:home/#{user}/#{domain}/git/#
 {application}.git
 set :deploy_to, /home/#{user}/#{domain}
 set :deploy_via, :remote_cache
 set :scm, 'git'
 set :branch, 'master'
 set :git_shallow_clone, 1
 set :scm_verbose, true
 set :use_sudo, false

 server domain, :app, :web
 role :db, domain, :primary = true

 namespace :deploy do
   task :restart do
     run touch #{current_path}/tmp/restart.txt
   end
 end

 I am guessing my path to my git repository is incorrect but I checked
 many ... many times and this is my path on my host.

 Any help would be greatly appreciated, thank you

 Olivier
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To post to this group, send email to rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~--~~~~--~~--~--~---



[Rails] Re: I get “Missing these required gems”, but gems are installed

2009-02-14 Thread Freddy Andersen

Gems might be installed in more than one area.

Look in ~/.gems and make sure that you use sudo when installing gems.

Do you now have multiple ruby directories on your mac? if so you most
likely have multiple gems directories too...

what I found was best when I upgraded from 1.8.6 to 1.8.7 was to
remove all gems directories and start empty. I can't remember what the
issue was but it was a path issue or something like that.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To post to this group, send email to rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~--~~~~--~~--~--~---



[Rails] Re: Two-to-one mappings

2009-02-14 Thread Maurício Linhares

Imagining that every round must belong to a room, here's a simple and
straightforward implementation:

class Room  ActiveRecord::Base
  # this class needs a max_rounds and rounds_count integer columns
  has_many :rounds

  def accepts_more_rounds?
max_rounds  rounds_count
  end

end

class Round  ActiveRecord::Base
  # this class needs a room_id integer column
  belongs_to :room, :counter_cache = true

  validate_on_create :validate_rounds_count

  protected

  def validate_rounds_count
self.room.reload
unless self.room.accepts_more_rounds?
  errors.add( :room, has already met it's rounds limit )
end
  end


end

room = Room.create( :max_rounds = 2 )
round_1 = room.rounds.create( :name = 'round 1' )
round_2 = room.rounds.create( :name = 'round 2' )
round_3 = room.rounds.create( :name = 'round 3' ) # this one isn't
going to be created
round_3.new_record? == true


-
Maurício Linhares
http://alinhavado.wordpress.com/ (pt-br) | http://blog.codevader.com/ (en)



On Sat, Feb 14, 2009 at 7:53 PM, Greg Brockman
gregory.brock...@gmail.com wrote:

 Hey all,

 I have a pretty simple question, but I'm not sure of a good solution
 to it.  Essentially, I want to provide a two-to-one mapping of models.
  I'm working on an application for a contest, where every (unordered)
 combination of two Rounds is supposed to be assigned to one Room.  Any
 Room might have many different combinations of Rounds, however.

 What is the Right Way of doing this in Rails?  Maybe create a model
 that holds the associated foreign keys?  Also, what would be a good
 way to scale this out, if I wanted to be able to map unordered
 n-element collections of Rounds to obtain a Room?

 Thanks,

 Greg

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To post to this group, send email to rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~--~~~~--~~--~--~---



[Rails] Re: Two-to-one mappings

2009-02-14 Thread Harold

That's a clean solution, however I don't know if it satisfies the fact
that any Room might have many different combinations of Rounds

Not sure I understand correctly, but if a room can have many
combination of rounds, and each combination of rounds has more than
one round, you could try this:

Room and Round models I assume you already have. A room can have many
round_combinations (create the RoundCombination model with a room_id.
Room :has_many :room_combinations, and
RoomCombination :belongs_to :room). Then create a join table between
round_combinations and rounds (HABTM).

You can use callbacks or validation to limit the relationship to two
rounds maximum.

On Feb 14, 11:42 pm, Maurício Linhares mauricio.linha...@gmail.com
wrote:
 Imagining that every round must belong to a room, here's a simple and
 straightforward implementation:

 class Room  ActiveRecord::Base
   # this class needs a max_rounds and rounds_count integer columns
   has_many :rounds

   def accepts_more_rounds?
     max_rounds  rounds_count
   end

 end

 class Round  ActiveRecord::Base
   # this class needs a room_id integer column
   belongs_to :room, :counter_cache = true

   validate_on_create :validate_rounds_count

   protected

   def validate_rounds_count
     self.room.reload
     unless self.room.accepts_more_rounds?
       errors.add( :room, has already met it's rounds limit )
     end
   end

 end

 room = Room.create( :max_rounds = 2 )
 round_1 = room.rounds.create( :name = 'round 1' )
 round_2 = room.rounds.create( :name = 'round 2' )
 round_3 = room.rounds.create( :name = 'round 3' ) # this one isn't
 going to be created
 round_3.new_record? == true

 -
 Maurício Linhareshttp://alinhavado.wordpress.com/(pt-br) 
 |http://blog.codevader.com/(en)

 On Sat, Feb 14, 2009 at 7:53 PM, Greg Brockman

 gregory.brock...@gmail.com wrote:

  Hey all,

  I have a pretty simple question, but I'm not sure of a good solution
  to it.  Essentially, I want to provide a two-to-one mapping of models.
   I'm working on an application for a contest, where every (unordered)
  combination of two Rounds is supposed to be assigned to one Room.  Any
  Room might have many different combinations of Rounds, however.

  What is the Right Way of doing this in Rails?  Maybe create a model
  that holds the associated foreign keys?  Also, what would be a good
  way to scale this out, if I wanted to be able to map unordered
  n-element collections of Rounds to obtain a Room?

  Thanks,

  Greg
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To post to this group, send email to rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~--~~~~--~~--~--~---



[Rails] conditions on association include, hacky but more or less solved

2009-02-14 Thread Chris

Hi all,

I just finally figured out how to get 2.2.2 to do this, and thought
I'd share in case others run into the same thing.

The situation is a find with associations, but the tricky part is that
the association shouldn't always be loaded. This is similar to putting
a condition on a has_many association in a model, but the condition is
dynamic rather than predefined.

The situation I had is

@entity = Entity.find(params[:id])
@traits = Trait.find :all,
 :include = [:trait_values = [:key_factors]]

but I only want the key_factors that connect to the given entity to be
loaded.

E.g. I have entities Jane and Marco, and traits Height (with values
Short, Medium, and Tall) and HairColor (with values Red, Brown, and
Black). Key factors connect an entity with a trait value and an
additional descriptor; if Jane is very tall and has reddish-brown hair
there would be three key factors Jane-Tall(Height)-Very, Jane-Red
(HairColor)-Somewhat, and Jane-Brown(HairColor)-Somewhat.  I want an
admin to be able to specify / alter the key factors, so I need to show
all the trait values and also the current key factors if they exist.
For entity Jane I would want
Height.Short -- key factor not loaded here
Height.Medium -- key factor not loaded here
Height.Tall.Very-- key factor IS loaded here
HairColor.Red.Somewhat  -- key factor IS loaded here
HairColor.Brown.Somewhat   -- key factor IS loaded here
HairColor.Black-- key factor not loaded here
and for Marco I'd want
Height.Short
Height.Medium
Height.Tall
HairColor.Red
HairColor.Brown
HairColor.Black

In SQL this would be represented by a condition in the join clause:
...
FROM `traits`
LEFT OUTER JOIN `trait_values` ON trait_values.trait_id = traits.id
LEFT OUTER JOIN `key_factors` ON key_factors.trait_value_id =
trait_values.id
AND
key_factors.entity_...@entity.id

There are two steps to getting this effect. First, you have to get the
associations to load in a single query. Second, you have to get the
condition into the join clause.

 By default in 2.2.2 associations are loaded in follow up queries.
That is, for
@traits = Trait.find :all,
 :include = [:trait_values = [:key_factors]]
you'd get three separate queries (with different where clauses - I
have a small, testing data set loaded), one to load the traits, one to
load the associated trait values, and one to load the key factors
associated with those values:
SELECT `traits`.* FROM `traits`
SELECT `trait_values`.* FROM `trait_values` WHERE
(`trait_values`.trait_id = 1)
SELECT `key_factors`.* FROM `key_factors` WHERE
(`key_factors`.trait_value_id IN (1,2))

To get that as a single query you need to add dummy conditions to your
find that mention the join tables:
@traits = Trait.find :all,
 :include = [:trait_values =
[:key_factors]],
 :conditions = trait_values.trait_id =
traits.id AND key_factors.id = key_factors.id
which then produces SQL like:
FROM `traits`
LEFT OUTER JOIN `trait_values` ON trait_values.trait_id = traits.id
LEFT OUTER JOIN `key_factors` ON key_factors.trait_value_id =
trait_values.id
WHERE (trait_values.trait_id = traits.id AND key_factors.id =
key_factors.id)

Now that final join clause needs to be specified slightly differently
(it needs another condition) - this is where it get's hacky. Various
experimentation in trying to solve this problem showed that the
association based includes are specified before anything in a joins
field, AND the contents of the joins field is directly appended. So,
the relevant condition can be specified there, and it will be appended
to the auto-generated join.
@traits = Trait.find :all,
 :include = [:trait_values =
[:key_factors]],
 :joins =  AND
key_factors.entity_id=+...@entity.id.to_s,
 :conditions = trait_values.trait_id =
traits.id AND key_factors.id = key_factors.id
This generates
FROM `traits`
LEFT OUTER JOIN `trait_values` ON trait_values.trait_id = traits.id
LEFT OUTER JOIN `key_factors` ON key_factors.trait_value_id =
trait_values.id
   AND
key_factors.entity_id=2
WHERE (trait_values.trait_id = traits.id
  AND key_factors.id = key_factors.id)
which almost works. The last thing to do is adjust the where
conditions to account for the fact that the key_factors may not be
there.
@traits = Trait.find :all,
 :include = [:trait_values =
[:key_factors]],
 :joins =  AND
key_factors.entity_id=+...@entity.id.to_s,
 :conditions = trait_values.trait_id =
traits.id
AND IFNULL

[Rails] Re: Undefined method 'parameters' on controller.request

2009-02-14 Thread Michael J. I. Jackson

How do I pass the controller through so that a method like  
template_format will pick it up and use it? Or is there some way to  
avoid that method being called altogether?

Thanks,

Michael

On Feb 14, 2009, at 8:27 AM, Julian Leviston wrote:


 Actionmailer is a bit different because the mail has it's own view
 which has no controller. You'd have to pass the controller in through
 the message to the mail when you're delivering or building it.

 Blog: http://random8.zenunit.com/
 Learn rails: http://sensei.zenunit.com/

 On 14/02/2009, at 9:10 AM, Michael J. I. Jackson
 mjijack...@gmail.com wrote:


 I'm getting a NoMethodError using Rails 2.1.0 when trying to send an
 email using ActionMailer. The error is being thrown from the
 template_format method in ActionView's base.rb file. Apparently the
 controller.request object is an instance of DummyClass (according to
 the exception trace) instead of ActionController::Request, and
 therefore does not have any useful methods associated with it.

 Right now I'm thinking that because the ActionMailer doesn't actually
 represent a separate request per se, that the request object is not
 being created correctly. Thus, when it goes to create the email using
 the template, it doesn't really know what format to use. Just a  
 hunch.

 I'm kind of a Rails newb, so any help with this issue would be  
 greatly
 appreciated. Just let me know if you need to know any other
 information.

 Michael




 


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To post to this group, send email to rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~--~~~~--~~--~--~---



[Rails] inserting a form on a page when button pressed

2009-02-14 Thread Adam Akhtar

Ive googled this and searched here and other forums but not getting
appropriate reuslts. Perhaps someone on the board can help.

All i want to do is to have a button/link on a page such as add task
which when pressed will insert the appropriate form plus fields directly
under the button/link. Im  wondering do i use use remote_link_for for
this and if it will link back to the current views controller right? or
is there a simpler way of doing this.

IF on the same page i had varius links of this sort such as add task,
expand table, collapse table and they all linked back to the same
controller action, how would i diferentiate between them. Would the
logic be in the controller opening up different rjs files or would it be
in teh one rjs file?

Any help on any of the points would help me out a lot!
-- 
Posted via http://www.ruby-forum.com/.

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To post to this group, send email to rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~--~~~~--~~--~--~---



[Rails] Re: Two-to-one mappings

2009-02-14 Thread Greg

Cool!  Harold, your solution strikes me as being exactly the way to do
it.  I've implemented it, and things seem to be sailing smoothly.
Thanks a lot to both of you.

Sincerely,

Greg

On Feb 14, 11:47 pm, Harold harold.gime...@gmail.com wrote:
 That's a clean solution, however I don't know if it satisfies the fact
 that any Room might have many different combinations of Rounds

 Not sure I understand correctly, but if a room can have many
 combination of rounds, and each combination of rounds has more than
 one round, you could try this:

 Room and Round models I assume you already have. A room can have many
 round_combinations (create the RoundCombination model with a room_id.
 Room :has_many :room_combinations, and
 RoomCombination :belongs_to :room). Then create a join table between
 round_combinations and rounds (HABTM).

 You can use callbacks or validation to limit the relationship to two
 rounds maximum.

 On Feb 14, 11:42 pm, Maurício Linhares mauricio.linha...@gmail.com
 wrote:

  Imagining that every round must belong to a room, here's a simple and
  straightforward implementation:

  class Room  ActiveRecord::Base
    # this class needs a max_rounds and rounds_count integer columns
    has_many :rounds

    def accepts_more_rounds?
      max_rounds  rounds_count
    end

  end

  class Round  ActiveRecord::Base
    # this class needs a room_id integer column
    belongs_to :room, :counter_cache = true

    validate_on_create :validate_rounds_count

    protected

    def validate_rounds_count
      self.room.reload
      unless self.room.accepts_more_rounds?
        errors.add( :room, has already met it's rounds limit )
      end
    end

  end

  room = Room.create( :max_rounds = 2 )
  round_1 = room.rounds.create( :name = 'round 1' )
  round_2 = room.rounds.create( :name = 'round 2' )
  round_3 = room.rounds.create( :name = 'round 3' ) # this one isn't
  going to be created
  round_3.new_record? == true

  -
  Maurício Linhareshttp://alinhavado.wordpress.com/(pt-br) 
  |http://blog.codevader.com/(en)

  On Sat, Feb 14, 2009 at 7:53 PM, Greg Brockman

  gregory.brock...@gmail.com wrote:

   Hey all,

   I have a pretty simple question, but I'm not sure of a good solution
   to it.  Essentially, I want to provide a two-to-one mapping of models.
    I'm working on an application for a contest, where every (unordered)
   combination of two Rounds is supposed to be assigned to one Room.  Any
   Room might have many different combinations of Rounds, however.

   What is the Right Way of doing this in Rails?  Maybe create a model
   that holds the associated foreign keys?  Also, what would be a good
   way to scale this out, if I wanted to be able to map unordered
   n-element collections of Rounds to obtain a Room?

   Thanks,

   Greg
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To post to this group, send email to rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~--~~~~--~~--~--~---



[Rails] Re: Two-to-one mappings

2009-02-14 Thread Harold A . Giménez Ch .
Great! Glad it worked.

On Sun, Feb 15, 2009 at 1:57 AM, Greg gregory.brock...@gmail.com wrote:


 Cool!  Harold, your solution strikes me as being exactly the way to do
 it.  I've implemented it, and things seem to be sailing smoothly.
 Thanks a lot to both of you.

 Sincerely,

 Greg

 On Feb 14, 11:47 pm, Harold harold.gime...@gmail.com wrote:
  That's a clean solution, however I don't know if it satisfies the fact
  that any Room might have many different combinations of Rounds
 
  Not sure I understand correctly, but if a room can have many
  combination of rounds, and each combination of rounds has more than
  one round, you could try this:
 
  Room and Round models I assume you already have. A room can have many
  round_combinations (create the RoundCombination model with a room_id.
  Room :has_many :room_combinations, and
  RoomCombination :belongs_to :room). Then create a join table between
  round_combinations and rounds (HABTM).
 
  You can use callbacks or validation to limit the relationship to two
  rounds maximum.
 
  On Feb 14, 11:42 pm, Maurício Linhares mauricio.linha...@gmail.com
  wrote:
 
   Imagining that every round must belong to a room, here's a simple and
   straightforward implementation:
 
   class Room  ActiveRecord::Base
 # this class needs a max_rounds and rounds_count integer columns
 has_many :rounds
 
 def accepts_more_rounds?
   max_rounds  rounds_count
 end
 
   end
 
   class Round  ActiveRecord::Base
 # this class needs a room_id integer column
 belongs_to :room, :counter_cache = true
 
 validate_on_create :validate_rounds_count
 
 protected
 
 def validate_rounds_count
   self.room.reload
   unless self.room.accepts_more_rounds?
 errors.add( :room, has already met it's rounds limit )
   end
 end
 
   end
 
   room = Room.create( :max_rounds = 2 )
   round_1 = room.rounds.create( :name = 'round 1' )
   round_2 = room.rounds.create( :name = 'round 2' )
   round_3 = room.rounds.create( :name = 'round 3' ) # this one isn't
   going to be created
   round_3.new_record? == true
 
   -
   Maurício 
   Linhareshttp://alinhavado.wordpress.com/(pt-br)http://alinhavado.wordpress.com/%28pt-br%29|
 http://blog.codevader.com/(en) http://blog.codevader.com/%28en%29
 
   On Sat, Feb 14, 2009 at 7:53 PM, Greg Brockman
 
   gregory.brock...@gmail.com wrote:
 
Hey all,
 
I have a pretty simple question, but I'm not sure of a good solution
to it.  Essentially, I want to provide a two-to-one mapping of
 models.
 I'm working on an application for a contest, where every (unordered)
combination of two Rounds is supposed to be assigned to one Room.
  Any
Room might have many different combinations of Rounds, however.
 
What is the Right Way of doing this in Rails?  Maybe create a model
that holds the associated foreign keys?  Also, what would be a good
way to scale this out, if I wanted to be able to map unordered
n-element collections of Rounds to obtain a Room?
 
Thanks,
 
Greg
 


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Talk group.
To post to this group, send email to rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~--~~~~--~~--~--~---