[Rails] Destroy method link_to show

2012-11-21 Thread Soichi Ishida
Rails 3.1.3

I have User model and Plan model

User has the following association

  has_many :gives, :class_name => "Plan", :foreign_key => :give_id,
:dependent => :destroy

And a view generates

 <% @user.gives.each do |give| %>
   ...
   <%= link_to 'Delete',  {:controller => :plans,  :action =>
:destroy, :id => give.id}, confirm: 'Are you sure?', :class=>'btn
btn-mini'  %>
   ...

It is not Plan's view, so I specified :controller as well.

This Delete link somehow leads to Plan show action.  It does not delete
it as I want it to.

Do you see any problem here ?

Honestly, I don't know what else to show you in order to find the
problem. If more information is needed, please let me know.

Thanks

soichi

-- 
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 https://groups.google.com/groups/opt_out.




Re: [Rails] Re: Opinion on a particular use of Initializers

2012-11-21 Thread Jordon Bedwell
On Wed, Nov 21, 2012 at 8:57 PM, Alex Braha Stoll
 wrote:
> Thanks for the answer, Fred.
>
> When you say lazily loading the data I need you mean waiting for a first
> request that uses the data, right? If so, how can I do that in a way that
> the data will persist for the next requests (from the same and from other
> users)? Just storing the data into a class that checks if the constants were
> already fetch doesn't guarantee the persistence of the data between
> requests, right? Can you point me a resource where I can learn more about a
> solution for my scenario?

Most objects should persist between requests so if you were to create
a struct and load all your data onto that struct the object would be
persisted between requests.  You could just create a Persist object
with an initializer and and there is your persistent struct.

-- 
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 https://groups.google.com/groups/opt_out.




[Rails] Re: Opinion on a particular use of Initializers

2012-11-21 Thread Alex Braha Stoll
Thanks for the answer, Fred.

When you say lazily loading the data I need you mean waiting for a first 
request that uses the data, right? If so, how can I do that in a way that 
the data will persist for the next requests (from the same and from other 
users)? Just storing the data into a class that checks if the constants 
were already fetch doesn't guarantee the persistence of the data between 
requests, right? Can you point me a resource where I can learn more about a 
solution for my scenario?

Cheers,

Alex.

Em quarta-feira, 21 de novembro de 2012 20h41min25s UTC-2, Frederick Cheung 
escreveu:
>
>
>
> On Wednesday, November 21, 2012 5:57:15 PM UTC, Alex Braha Stoll wrote:
>>
>>
>> Since the profile ids (and other 'constants' stored in the database) can 
>> only change if the sys admin changes their values before the deploy 
>> (editing seeds.rb), I though of using initializers to retrieve references 
>> to all those database constants (therefore opening less connections with 
>> the database during application usage):
>>
>> I don't think this will affect the number of connections to the database, 
> although you will of course save some queries
>  
>
>>
>> I have tested this solution and it works perfectly fine. However, I would 
>> like to know from veteran Rails developers if this is a good (or 
>> acceptable) use of initializers (and if this should really increase 
>> performance).
>>
>>
> Personally if this was worthwhile for my app I would load the profiles 
> lazily rather than in an initializer.  One reason is that initializers get 
> run in a lot of cases where you probably don't need those rows cached, eg 
> rake routes.
> Occasionally this sort of stuff can bite you too - depending on how you 
> deploy the app, the profiles table might not exist (fresh deploy). So you 
> run rake db:schema:load to set things up, but that would also load you 
> initializer and would therefore blow up when that initializer tried to 
> access the profiles table.
>
> Fred 
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msg/rubyonrails-talk/-/Zup5h2klZPQJ.
For more options, visit https://groups.google.com/groups/opt_out.




Re: [Rails] File sharing site tutorial?

2012-11-21 Thread Walter Lee Davis

On Nov 21, 2012, at 5:55 PM, John Dunlap wrote:

> Thanks for the super informative post! I've done the very basics of 
> rails, and I'm honing my Ruby language skills at the moment (I've heard 
> it's a bad stereotype, that people learn RoR for before Ruby itself)
> 
> I'm guessing Amazon cloud is good cloud hosting for this sort of thing?

Sure, or EngineYard or Rackspace. Lots of clouds out there. If you're just 
getting started and testing it out, you cannot go wrong with Heroku. Deployment 
is as easy as a git-push. The starting price is free. 

Walter

> 
> -- 
> 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 https://groups.google.com/groups/opt_out.
> 
> 

-- 
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 https://groups.google.com/groups/opt_out.




[Rails] Re: Question about Active Record

2012-11-21 Thread Alexandra E Paredes T
Fred thanks for the response, a friend and I did some tests and found some 
useful info. Altough we're now wondering what would it happen if we decide 
not to work with ActiveRecord on RoR, what features of the framework we're 
going to lose?

El sábado, 17 de noviembre de 2012 05:02:53 UTC-4:30, Frederick Cheung 
escribió:
>
>
>
> On Nov 16, 2:05 pm, Alexandra E Paredes T <05-38...@usb.ve> wrote: 
> > Good Morning, 
> > 
> > I'm an student of Computer Engineering from Simón Bolívar University, in 
> > Caracas Venezuela. I'm working in my thesis about ORM and their 
> > "respectfulness" on databases. In order to have a better understanding 
> of 
> > the Ruby on Rails ORM, I'm wondering where do I can read about the 
> > low-level methods of the ORM, or what module can I study to see that. 
> Why 
> > I'm looking for is something like how ActiveRecords translates for 
> example 
> > an search on SQL. 
> > 
>
> Sounds like you want to be looking at the arel gem and at 
> ActiveRecord::Relation 
>
> Fred 
>
> > In advance, thank you very much. 
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msg/rubyonrails-talk/-/EPPU6QUC25oJ.
For more options, visit https://groups.google.com/groups/opt_out.




[Rails] Re: File sharing site tutorial?

2012-11-21 Thread John Dunlap
Thanks for the super informative post! I've done the very basics of 
rails, and I'm honing my Ruby language skills at the moment (I've heard 
it's a bad stereotype, that people learn RoR for before Ruby itself)

I'm guessing Amazon cloud is good cloud hosting for this sort of thing?

-- 
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 https://groups.google.com/groups/opt_out.




Re: [Rails] File sharing site tutorial?

2012-11-21 Thread Walter Lee Davis

On Nov 21, 2012, at 4:57 PM, John Dunlap wrote:

> I've been thinking of doing a RoR application for a file sharing site a
> la imgur, but for other kinds of files (Namely 3D modeling stuff.) Is
> there a decent tutorial for this sort of app? I've been told that
> paperclip for ruby might be a decent place to start, but I could see a
> lot of landmines in this sort of app.
> 
> Sorry in advance if this gets asked twice a day - this is my first post.

Welcome! If you haven't already, please do yourself an enormous favor and work 
all the way through Michael Hartl's Rails Tutorial. It's free to use on line, 
and there are for-pay screencasts and PDF materials, too. 
http://railstutorial.org

Then, have a look at http://ruby-toolbox.com, where you can find a bunch of 
categorized Gems and Engines for almost any sort of task. Paperclip is really 
good, well tested and mature. I also really like Dragonfly, but the best case 
for that one is any time you don't know up front how large you may want to show 
your images. It allows you to lazy-thumbnail to any dimension after the image 
has been uploaded and stored. Finally, there's also CarrierWave, which I've 
used once, and liked a lot. All of these allow you to use a cloud storage 
option, so you don't have to worry about your server filling up and 'sploding.

Walter

> 
> -- 
> 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 https://groups.google.com/groups/opt_out.
> 
> 

-- 
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 https://groups.google.com/groups/opt_out.




[Rails] Re: Opinion on a particular use of Initializers

2012-11-21 Thread Frederick Cheung


On Wednesday, November 21, 2012 5:57:15 PM UTC, Alex Braha Stoll wrote:
>
>
> Since the profile ids (and other 'constants' stored in the database) can 
> only change if the sys admin changes their values before the deploy 
> (editing seeds.rb), I though of using initializers to retrieve references 
> to all those database constants (therefore opening less connections with 
> the database during application usage):
>
> I don't think this will affect the number of connections to the database, 
although you will of course save some queries
 

>
> I have tested this solution and it works perfectly fine. However, I would 
> like to know from veteran Rails developers if this is a good (or 
> acceptable) use of initializers (and if this should really increase 
> performance).
>
>
Personally if this was worthwhile for my app I would load the profiles 
lazily rather than in an initializer.  One reason is that initializers get 
run in a lot of cases where you probably don't need those rows cached, eg 
rake routes.
Occasionally this sort of stuff can bite you too - depending on how you 
deploy the app, the profiles table might not exist (fresh deploy). So you 
run rake db:schema:load to set things up, but that would also load you 
initializer and would therefore blow up when that initializer tried to 
access the profiles table.

Fred 

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msg/rubyonrails-talk/-/LKGNT_jwrzkJ.
For more options, visit https://groups.google.com/groups/opt_out.




[Rails] Opinion on a particular use of Initializers

2012-11-21 Thread Alex Braha Stoll
Hi!

In the Rails app I'm developing I have some data stored in the database 
that acts like constants. For example, I populate a profiles table with all 
the profile types using seeds.rb. To avoid hardcoding the profile ids in my 
code, everytime I needed to do an operation involving a profile type I 
first retrieved the profile type from the database:


admin = Profile.find_by_name('admin')
@all_admins = admin.people


Since the profile ids (and other 'constants' stored in the database) can 
only change if the sys admin changes their values before the deploy 
(editing seeds.rb), I though of using initializers to retrieve references 
to all those database constants (therefore opening less connections with 
the database during application usage):

in .../initializers/


class DatabaseConstants < ActiveRecord::Base
  
  # loading the profiles
  temp_profiles = {}
  Profile.all.each do |profile|
case profile.name
  
when 'foo'
  temp_profiles[:foo] = profile

when 'bar'
  temp_profiles[:bar] = profile
  
when 'admin'
  temp_profiles[:admin] = profile
  
when 'super-admin'
  temp_profiles[:super_admin] = profile
end   
  end
  PROFILES = temp_profiles
  
  # other 'constants' to be loaded
  # ... 
end


and then, I can do something like the following in a controller:


@all_admins = DatabaseConstants::PROFILES[:admin].people


I have tested this solution and it works perfectly fine. However, I would 
like to know from veteran Rails developers if this is a good (or 
acceptable) use of initializers (and if this should really increase 
performance).

Cheers,

Alex.

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msg/rubyonrails-talk/-/bmtvpHG8CykJ.
For more options, visit https://groups.google.com/groups/opt_out.




[Rails] [JOBS] RoR Developer at SF Google-Backed Start Up

2012-11-21 Thread Nathan Visconti
The Climate Corporation is a Google Ventures funded big data startup with a 
mission to help people adapt to climate change. We make sense of huge 
amounts of complicated data and run simulations  to 
determine the risk of adverse weather, which influences 25% of GDP. 
We are looking for a Web Application Developer who are passionate about 
innovation and share the value in our mission. You can read more about the 
position below. If you are interested, either email your resume to 
nvisco...@climate.com, or apply online at climate.com/company/careers. *
*

*What you will do:*

   - You won’t be bored working with just ActiveRecord. You’ll get to learn 
   something new, like: EventMachine, Goliath, etc.
   - You will learn to break up a large monolithic legacy Rails application 
   into small, testable, and well-designed functional units
   - You will employ test-driven and behavior-driven development
   - You will be working in a service-oriented architectures and learn how 
   to create/use service APIs
   - Participate in daily stand-ups, sprint planners, reviews, 
   retrospectives, and the occasional ping-pong game

*What you bring to the table:*

   - Experience building transactional systems with Rails, Ruby, MySQL
   - Experience with deployment  in distributed environments and are 
   familiar with the associated challenges
   - Intuitively understand web technologies and web application 
   architectures
   - Familiar with RSpec, Cucumber
   - Are creative, self-motivated and able to prioritize & get things done
   - Have contributed to an open source effort
   - Write elegant, maintainable and easy-to-follow code
   - BS, MS or equivalent in Computer Science or related technical field
   - At least one year of experience developing web apps in Ruby, Python, 
   Java or Clojure
   - Team player who feels at home in an open and flat-structured 
   environment, and takes pride in a job well done

*What We Offer:*

Our team is composed of some of the most brilliant interdisciplinary minds 
in the industry. Climatology Specialists, Big Data Engineers, 
Mathematicians, Front end Application Engineers and more work together to 
create the most forward thinking technology in the industry. The 
environment is extremely engaging and fast-paced, with dozens of 
specialties coming together to provide the best product possible product 
and experience for our customers.  As Mark Twain said, “A great deal has 
been said about the weather, but very little has been done about it.” Our 
goal is to change that.

   - Competitive salary, excellent benefits, and some of the best perks in 
   the industry, including:
   - Generous stock options. Our success is your success.
   - Catered lunch 5 days a week from a varied array of San Francisco 
   eateries
   - Endless snacks and company-paid dinner
   - “3-On 1-Off” Sprints. That means that 25% of your time is spent 
   working on your own innovations for the company.
   - Company sponsored outings, including go-kart races, kayaking, holiday 
   yacht parties, and sporting events, etc.
   - An always-stocked kegerator
   - Energetic idea-driven work environment with an exciting culture
   - Exciting world-changing opportunity - we are solving problems that 
   have a massive impact on the world
   - A driven, talented team that aims to make a large-scale impact through 
   an innovative technology platform

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msg/rubyonrails-talk/-/RYkVootueZwJ.
For more options, visit https://groups.google.com/groups/opt_out.




[Rails] I Dont like it but i have to do it

2012-11-21 Thread Moises Zaragoza
 

I need to open access to a no username and password to my application. 

What i did was i added a *userkey* field on my users model that can be past 
via a get or post method from another site. 
that will then find the correct user and log them in as if they had put in 
there user name and password. 

Now i am using device to log in my users. but i am not sure where to append 
the second login method. 

in my user controller i have 

*def login_bypass
id = params[:id]
@u = User.find_by_**userkey(id) 
   
if @u == nil
  flash[:error] = t(:please_contact_support)
 
  redirect_to login_path

else

// device log in with @u info 
  flash[:success] = t(:welcome_to_the_site)
  redirect_to users_path
   
end
  end  *


any one know how should i go on?

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msg/rubyonrails-talk/-/wm5xlloH5IIJ.
For more options, visit https://groups.google.com/groups/opt_out.




[Rails] Re: Pessimistic locking locks the entire table?

2012-11-21 Thread Frederick Cheung


On Wednesday, November 21, 2012 7:24:05 PM UTC, jmcguckin wrote:
>
> What happens when a 2nd process tries to write to a record/table that is 
> locked? Does it stall until the lock is released or
> does it throw an exception?
>
>
It will block until the lock is released. If the lock is never released, 
depending on your database settings, it will give up at some point and 
throw an exception

Fred

 

>
> On Friday, April 6, 2012 3:18:37 AM UTC-7, Frederick Cheung wrote:
>>
>>
>>
>> On Apr 4, 12:47 am, PierreW  wrote: 
>> > I don't know if using pessimistic locking is the best way to do it, 
>> > but here is why I used this: 
>> > 
>> > - every X hours a demon runs and updates records 
>> > - thing is, this demon "action" can last Y with Y > X 
>> > 
>> > So there is a risk that two instances of the demon try to update the 
>> > same record. So each demon needs to acquire the lock before they can 
>> > do anything on a given record. 
>> > 
>> > I guess an alternative could be to try and make sure that a demon only 
>> > starts if the previous one has finished but this was not an option in 
>> > my case. 
>> > 
>>
>> You might want to look at separating the concept of the SQL lock 
>> (which do have costs, can land you with deadlocks etc) from the 
>> application level lock. 
>>
>> You could have a locked column (better a locked_since column) that 
>> indicates that the row is locked. Use optimistic or pessimistic 
>> locking to update the locked_since column, and make your update stuff 
>> ignore records with a non null locked_since 
>>
>>
>> Fred 
>>
>> > On Apr 4, 12:37 am, Robert Walker  wrote: 
>> > 
>> > 
>> > 
>> > 
>> > 
>> > 
>> > 
>> > > wam r. wrote in post #1054714: 
>> > 
>> > > > Hi guys, 
>> > 
>> > > > I must be missing something obvious with pessimistic locking. Here 
>> is 
>> > > > what I do (Rails 2.3, mySQL): 
>> > 
>> > > So is there a reasonable use case for pessimistic locking on a web 
>> > > application? That seems insane to me. 
>> > 
>> > > -- 
>> > > 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.
To view this discussion on the web visit 
https://groups.google.com/d/msg/rubyonrails-talk/-/ojiyicYrijcJ.
For more options, visit https://groups.google.com/groups/opt_out.




[Rails] File sharing site tutorial?

2012-11-21 Thread John Dunlap
I've been thinking of doing a RoR application for a file sharing site a
la imgur, but for other kinds of files (Namely 3D modeling stuff.) Is
there a decent tutorial for this sort of app? I've been told that
paperclip for ruby might be a decent place to start, but I could see a
lot of landmines in this sort of app.

Sorry in advance if this gets asked twice a day - this is my first post.

-- 
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 https://groups.google.com/groups/opt_out.




[Rails] JOBS IN GERMANY

2012-11-21 Thread Rocío C.
Hello,

I´m looking for Ruby and Rails developer for interesting job in Germany.
You can see the position in www.es.exrein.com

If you are intereste, please, send me your english cv to r...@exrein.com

Skills:

-2-3 years of experience in Ror,
-Fluent english
-Work permit for Germany (Blue Card) if you are foreing.

Thanks!!

-- 
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 https://groups.google.com/groups/opt_out.




[Rails] Re: Pessimistic locking locks the entire table?

2012-11-21 Thread jmcguckin
What happens when a 2nd process tries to write to a record/table that is 
locked? Does it stall until the lock is released or
does it throw an exception?


On Friday, April 6, 2012 3:18:37 AM UTC-7, Frederick Cheung wrote:
>
>
>
> On Apr 4, 12:47 am, PierreW  wrote: 
> > I don't know if using pessimistic locking is the best way to do it, 
> > but here is why I used this: 
> > 
> > - every X hours a demon runs and updates records 
> > - thing is, this demon "action" can last Y with Y > X 
> > 
> > So there is a risk that two instances of the demon try to update the 
> > same record. So each demon needs to acquire the lock before they can 
> > do anything on a given record. 
> > 
> > I guess an alternative could be to try and make sure that a demon only 
> > starts if the previous one has finished but this was not an option in 
> > my case. 
> > 
>
> You might want to look at separating the concept of the SQL lock 
> (which do have costs, can land you with deadlocks etc) from the 
> application level lock. 
>
> You could have a locked column (better a locked_since column) that 
> indicates that the row is locked. Use optimistic or pessimistic 
> locking to update the locked_since column, and make your update stuff 
> ignore records with a non null locked_since 
>
>
> Fred 
>
> > On Apr 4, 12:37 am, Robert Walker  wrote: 
> > 
> > 
> > 
> > 
> > 
> > 
> > 
> > > wam r. wrote in post #1054714: 
> > 
> > > > Hi guys, 
> > 
> > > > I must be missing something obvious with pessimistic locking. Here 
> is 
> > > > what I do (Rails 2.3, mySQL): 
> > 
> > > So is there a reasonable use case for pessimistic locking on a web 
> > > application? That seems insane to me. 
> > 
> > > -- 
> > > 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.
To view this discussion on the web visit 
https://groups.google.com/d/msg/rubyonrails-talk/-/qSI75OgjsmMJ.
For more options, visit https://groups.google.com/groups/opt_out.




Re: [Rails] is there a better DRY code writing for this scope ?

2012-11-21 Thread Dave Aronson
On Wed, Nov 21, 2012 at 8:33 AM, Erwin  wrote:

> I wrote this scope in my Subdomain model :
>
>   scope :in_account, lambda { |account_id|
> if account_id == "*"
>   where("account_id >= ?", 0)
> else
>   where(account_id: account_id)
> end
>   }
>
> where account_id == '*'  then all subdomain instances are selected
> when account_id is given , only subdomain instances in this account are
> selected
>
> is there a better writing ?

Try:

  scope :in_account, lambda { |account_id|
where(account_id: account_id) if account_id != "*"
  }

If the conditional fails, this will just not interfere with the query.

If it's possible that account_id will be nil or blank (as on a page
accessed w/o passing any params), tack "&& account_id.present?" onto
the conditional.

-Dave

-- 
Dave Aronson, the T. Rex of Codosaurus LLC,
secret-cleared freelance software developer
taking contracts in or near NoVa or remote.
See information at http://www.Codosaur.us/.

-- 
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 https://groups.google.com/groups/opt_out.




[Rails] Re: clue about deleting empty directories in a file structure ?

2012-11-21 Thread Erwin
[SOLVED]  found a better module extending FileUtils .. it works

module MyExtensions
  module FileUtils
# Gracefully delete dirs that are empty (or contain empty children).
def rmdir_empty(*dirs)
  dirs.each do |dir|
begin
  ndel = Dir.glob("#{dir}/**/", File::FNM_DOTMATCH).count do |d|
begin; Dir.rmdir d; rescue SystemCallError; end
  end
end while ndel > 0
  end
end
  end

  module ::FileUtils
extend FileUtils
  end
end


Le mercredi 21 novembre 2012 18:35:57 UTC+1, Erwin a écrit :
>
> I have been playing around w Dir and FileUtils, and I can delete the stuff 
> I want to get rid off , but then I get some empty folders 
> is there any way to remove ( recursively.. ) all empty folders ?
>
> I found a piece of code dated 2007 ... is there anything new around ?
>
> thanks for feedback
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msg/rubyonrails-talk/-/frIZqMforq0J.
For more options, visit https://groups.google.com/groups/opt_out.




[Rails] clue about deleting empty directories in a file structure ?

2012-11-21 Thread Erwin
I have been playing around w Dir and FileUtils, and I can delete the stuff 
I want to get rid off , but then I get some empty folders 
is there any way to remove ( recursively.. ) all empty folders ?

I found a piece of code dated 2007 ... is there anything new around ?

thanks for feedback

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msg/rubyonrails-talk/-/DSNP_KL1BxYJ.
For more options, visit https://groups.google.com/groups/opt_out.




Re: [Rails] right click or Context Menu in ruby without javascript

2012-11-21 Thread Walter Lee Davis

On Nov 21, 2012, at 12:21 AM, nikhil rn wrote:

> I finally decided to take up the right click using HTML5. Thank you all. 
> I referred David Walsh website for the 
> same(http://davidwalsh.name/html5-context-menu). Is there a way to 
> remove the system generated right click options?

You could trap them in JavaScript and return event.preventDefault() to stop the 
normal response from happening.

Have a google for the right way to trap a right-click -- it's very popular in 
anti-piracy scripts.

Walter

> 
> -- 
> 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 https://groups.google.com/groups/opt_out.
> 
> 

-- 
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 https://groups.google.com/groups/opt_out.




Re: [Rails] Nested Attributes in Rails 3

2012-11-21 Thread Colin Law
On 21 November 2012 12:28, Jinet  wrote:
>
> hi..
> im going to start learning ruby..now dont know even a single thing about
> ruby,,can anyone please suggest how to start learning..?
> thank you..

What has that got to do with the subject line (Nested Attributes in
Rails 3) and why have you posted a large message with many irrelevant
quoted lines?

You say you want to learn to use Ruby, but this is a Ruby on Rails
list so I assume you want to learn Ruby on Rails.
The answer is to start by working through a good rails tutorial such
as railstutorial.org (which is free to use online).  I assume you
already know the basics of html, if not then start there.
Also work on your google skills, I am sure that a search for learning
ruby rails would have given you many useful answers.

If you want to ask more then please start a new thread with an
appropriate subject line.

Colin

-- 
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 https://groups.google.com/groups/opt_out.




[Rails] Re: ice_cube 0.3.1

2012-11-21 Thread Tomasz Żewłakow
First of all, your plugin is just great!

Although:

How am I able to rule opening hours of a restaurant within single Schedule?
Mon-Fri 8-16 is quite easy but

schedule = Schedule.new(Time.parse(Date.yesterday.to_s + ' 8:00'), 
:duration => 60*60*8)
(...)
schedule.add_recurrence_rule Rule.daily.day(:wednesday)
schedule.add_recurrence_rule Rule.daily.day(:thursday)
(...)
raise schedule.occurring_at?(Time.now).inspect

Problem is when trying to rule something like:
Mon 9-17
Tu 16-01 (the next day after midnight)
etc.

Am I able to do this with that plugin?

W dniu piątek, 25 czerwca 2010 18:47:03 UTC+2 użytkownik John Crepezzi 
napisał:
>
> @mikrogroove 
>
> ice_cube v0.4 just came out with end time support and a few bug fixes. 
> I'm adding details for adding end_time to a schedule now 
>
> Thanks, 
> John C 
>
> On Jun 22, 10:25 pm, John Crepezzi  wrote: 
> > @mikrogroove 
> > 
> > I need a few days to finish up the testing, and then I'll have this 
> > out for you. 
> > Thanks for your patience! 
> > 
> > Also, check out the addition of :duration in the README, if you 
> > haven't already.  May help you get started 
> > 
> > Thanks, 
> > John Crepezzi 
> > 
> > On Jun 21, 10:36 am, mikrogroove  wrote: 
> > 
> > 
> > 
> > > @John: Just wanted to check if there's any progress on the end_times 
> > > support? 
> > 
> > > Many thanks, 
> > 
> > > mikrogroove 
> > 
> > > On 1 June, 22:50, mikrogroove  wrote: 
> > 
> > > > That is awesome news John, I am sure this will become a hugely 
> popular 
> > > > gem - it's almost a complete calendaring system in a box! I wish my 
> > > > skills were up to a level where I could offer to help, but I fear 
> I'd 
> > > > just mess things up for you :s Please know that your efforts are 
> > > > greatly appreciated! 
> > 
> > > > mikrogroove 
> > 
> > > > On 1 June, 22:19, John Crepezzi  wrote: 
> > 
> > > > > Yep, sinceice_cubeis made for occurrences and not durations - 
> you'd 
> > > > > have to store these separately.  I'm working with a branch now 
> that 
> > > > > will support end_times for rules, so you could call occurring_at? 
> > > > > (Time.now) on a rule and see if it occurs anywhere in the 
> duration. 
> > 
> > > > > I'll have this ready in the next few days 
> > > > > Thanks, 
> > > > > John C 
> > 
> > > > > On Jun 1, 3:02 pm, mikrogroove  wrote: 
> > 
> > > > > >  Hi John, 
> > 
> > > > > > Many thanks for your quick reply! I knew about the .until() 
> option, 
> > > > > > but it's not quite what I was after though. From the readme: 
> > > > > > "Individual rules may optionally specify an until date, which is 
> a 
> > > > > > date that that individual rule is no longer effective". I need 
> the 
> > > > > > rule to remain effective for the next occurrence of the event. 
> Think 
> > > > > > of it this way: what if I have a weekly meeting every Monday 
> between 
> > > > > > 9.30am and 10.30am and I do .occurs_at?(Time.now) on a Monday @ 
> 10am? 
> > > > > > What I'm after is a way to specify the duration of each 
> occurrence, 
> > > > > > but perhaps I'm better off storing this separately? But then how 
> to 
> > > > > > deal with a schedule with multiple rules (where each rule might 
> have a 
> > > > > > different duration)? 
> > 
> > > > > > Cheers, 
> > 
> > > > > > mikrogroove 
> > 
> > > > > > On 1 June, 15:14, John Crepezzi  
> wrote: 
> > 
> > > > > > > Mikro, 
> > 
> > > > > > > Thanks, I'm glad you like it :) 
> > 
> > > > > > > Individual rules can take an end date as follows: 
> > > > > > > rule = IceCube::Rule.weekly.until(Time.local(2010, 10, 6)) 
> > 
> > > > > > > Just a note: Until times are inclusive. 
> > 
> > > > > > > Hope this helps! 
> > > > > > > Thanks, 
> > > > > > > John Crepezzi  
> > 
> > > > > > > On Jun 1, 5:43 am, mikrogroove  wrote: 
> > 
> > > > > > > > This is a great gem, and probably the best starting point I 
> could have 
> > > > > > > > hoped for in order to meet my project's requirements - 
> thanks a 
> > > > > > > > million for putting it together! 
> > 
> > > > > > > > I'm dealing with recurring events which can be both stuff 
> like normal 
> > > > > > > > business hours (mon-fri 10-18 & sat 12-18) or more obscure 
> ones 
> > > > > > > > (second sunday of every month 12-19).  I've set up a simple 
> model and 
> > > > > > > > associated form which generates rules for the starting 
> times, and it 
> > > > > > > > all works very nicely indeed (I render the schedule to YAML 
> before 
> > > > > > > > storing in DB). But then *doh* it hits me: there is no way 
> to specify 
> > > > > > > > an end time other than the time when the recurring series as 
> a whole 
> > > > > > > > should end. How do I go about giving each recurring event a 
> time 
> > > > > > > > span? 
> > 
> > > > > > > > Many thanks, 
> > 
> > > > > > > > mikrogroove 
> > 
> > > > > > > > On 26 Apr, 23:25, John Crepezzi  
> wrote: 
> > 
> > > > > > > > > == Aboutice_cubeice_cubeis a time recurrence library for 
> Ruby. 

Re: [Rails] Nested Attributes in Rails 3

2012-11-21 Thread Jinet
hi..
im going to start learning ruby..now dont know even a single thing about
ruby,,can anyone please suggest how to start learning..?
thank you..
jinet

On 21 November 2012 11:59, Unni  wrote:

> Cheers !
>
>
> On Wed, Nov 21, 2012 at 11:55 AM, avinash behera <
> aavinash.beh...@gmail.com> wrote:
>
>> Its working now. Its my fault.
>> I forgot to remove an attribute's validation which I moved from User
>> model to Address model. There validation was failing.
>> Thanks for helping me out...
>>
>>
>> On Wed, Nov 21, 2012 at 11:46 AM, avinash behera <
>> aavinash.beh...@gmail.com> wrote:
>>
>>> In new :-
>>>
>>> @user = User.new
>>> @user.build_address # here is it required while building the page ?
>>>
>>> create :-
>>>
>>> @user = User.new(params[:user])
>>>  @user.save
>>> If I use build here, I am not getting those attributes present in
>>> address model in UI.
>>>
>>> Sorry I have communicated wrong. This is the controller
>>>
>>>
>>> On Wed, Nov 21, 2012 at 11:36 AM, Unni  wrote:
>>>
 *@user = User.new*
 *@user.build_profile*

 Is that all what you have in the controller in create action?

 *@user = User.new(params[:user]) *

 is what one would expect.

 On Wed, Nov 21, 2012 at 11:17 AM, avinash behera <
 aavinash.beh...@gmail.com> wrote:

> I tried with that. But somewhere validations are failing. I had
> dropped my db. Trying to create a user. But in console it says:
> User already exists.
> Not sure.
> In controller I have mentioned as @user.build_profile. Is it fine?
> & in erb file, I am using simple_form_for.
> So can we use fields_for there?
>
>
> On Wed, Nov 21, 2012 at 10:44 AM, Unni  wrote:
>
>> http://stackoverflow.com/a/3283404/1731232
>>
>>
>> http://api.rubyonrails.org/classes/ActiveModel/MassAssignmentSecurity/ClassMethods.html#method-i-attr_accessible
>>
>>
>> On Wed, Nov 21, 2012 at 10:31 AM, Jim Ruther Nill 
>> wrote:
>>
>>>
>>>
>>>
>>> On Wed, Nov 21, 2012 at 12:56 PM, avinash behera <
>>> aavinash.beh...@gmail.com> wrote:
>>>
 I didn't get this :-
 *attr_accessible :address_attributes*
 *
 *
 Why we need to define this in user.rb?
 We already have has_one relation. Will it not be accessing those
 attributes in address model automatically?

>>>
>>> fields_for uses _attributes as the name of the fields
>>> when you are using
>>> accepts_nested_attributes_for :association so you need to define
>>> this in attr_accessible
>>>
>>>


 On Wed, Nov 21, 2012 at 10:11 AM, Unni wrote:

> add
>
> *attr_accessible :address_attributes*
>
> in your model.
>
> Only the fields that you specify via attr_accessible, are open to
> mass assignment.
>
> Unni
>
> On Wed, Nov 21, 2012 at 10:02 AM, Avi 
> wrote:
>
>> Hello All,
>>
>> I am stuck in nested attributes:-
>> here is my code :-
>>
>> User.rb :-
>> has_one :address
>> accepts_nested_attributes_for :address
>>
>> Address.rb :-
>>
>> belongs_to :user
>>
>> _form.html.erb:-
>>
>> <%= simple_form_for @user ,:validate => true do |f| %>
>><%= f.fields_for :address do |d| %>
>>   <%= d.input :first_name %>
>>   <%= d.input :last_name %>
>>   <% end %>
>>   <%= f.input :email %>
>>  <% end %>
>>
>> in user_controller.rb:-
>> In new as well as create method I tried with:-
>> @user = User.new
>> @user.build_profile
>>
>> But still I am getting the error as :-
>>
>> Can't mass-assign protected attributes: address_attributes
>>
>> Any Suggestions ??
>>
>> 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.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msg/rubyonrails-talk/-/dd447A7hSYwJ.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>>
>>
>
>
>
> --
> Unni
>
>  --
> 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.
>>

Re: [Rails] Are Rail's database tools really helpful?

2012-11-21 Thread Scott Ribe
On Nov 21, 2012, at 3:56 AM, Denis BEURIVE wrote:

> Instead of writing a simple SQL request, you write a complicated set of
> methods' invocations (with options...).

1) the methods are not that complicate

2) if you wish, you can just write SQL instead and get objects back

-- 
Scott Ribe
scott_r...@elevated-dev.com
http://www.elevated-dev.com/
(303) 722-0567 voice




-- 
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 https://groups.google.com/groups/opt_out.




[Rails] Re: Are Rail's database tools really helpful?

2012-11-21 Thread Frederick Cheung
On Wednesday, November 21, 2012 10:56:58 AM UTC, Ruby-Forum.com User wrote:
>
>
> Instead of writing a simple SQL request, you write a complicated set of 
> methods' invocations (with options...). 
>
> The resulting code is not easy to read. You think : I should write an 
> easy to read SQL request! 
>
>
Not sure I buy that.

I'd far rather write

Garment.join(:brand).where(:brands => {:published => true}, :category_id => 
jumpers)

than

find_by_sql(['select * from garments
inner join brands on garments.brand_id = brands.id
where brands.published = true AND category_id = ?', jumpers)

And it only gets better as the query grows in complexity - building up 
strings is a pain in the arse, for example


Garment.where(criteria.reject {|k,v| v.blank?)

as opposed

to

criteria.collect |name, value|
  "#{connection.quote name} = #{connection.quote value}"
end.join( ' AND ')

 

> Some says : yes, but by using the database abstraction, you can change 
> you database easily (ex : from MySql to SQLServer)! 
>
> OK, but... Did you ever change your database ? 
>
> If you really need to migrate from MySql to SQLServer, then it means 
> that you have a *deep* problem. You may need to restructure your 
> database... 
>
> It's certainly true that changing database will always be a big effort, 
even if you write 0 lines of sql in your rails app.
 

> And what about "migrations" ? 
>
> Migrations keep track of structure's changes. OK, but why don't you just 
> keep your database's schema under SVN (or Git) ? 
>
>  
just storing the schema doesn't always tell you how to apply changes to 
that schema 

 

> Migrations can be used to change the database's content. OK, but 
> everything is not reversible. And, by the way, you should always work on 
> the testing environment. 
>
> So, my question is : 
>
> Do you really use all the Rails' tools to manage your database ? 
>
>  
I do
 

> Can you use Rails without Active Record ? 
>
>  
Absolutely. You could use data mapper for example or not use a SQL database 
at all. I've built apps that only used couchdb or mongo or that didn't have 
a persistence layer of their own at all.

Fred
 

> Thanks, 
>
> Denis 
>
> -- 
> 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.
To view this discussion on the web visit 
https://groups.google.com/d/msg/rubyonrails-talk/-/PrvbLyRglMYJ.
For more options, visit https://groups.google.com/groups/opt_out.




Re: [Rails] is there a better DRY code writing for this scope ?

2012-11-21 Thread Erwin
Great !

Thanks Jim

Le mercredi 21 novembre 2012 15:04:57 UTC+1, jim a écrit :
>
>
>
>
> On Wed, Nov 21, 2012 at 9:33 PM, Erwin >wrote:
>
>> I wrote this scope in my Subdomain model :
>>
>>   scope :in_account, lambda { |account_id|
>> if account_id == "*"
>>   where("account_id >= ?", 0)
>> else
>>   where(account_id: account_id) 
>> end
>>   }
>>
>> where account_id == '*'  then all subdomain instances are selected
>> when account_id is given , only subdomain instances in this account are 
>> selected
>>
>> is there a better writing ?
>>
>
> you can use scoped instead
>
> account_id == '*' ? scoped : where(account_id: account_id)  
>  
>
>>
>> thanks for feedback
>>
>>  -- 
>> 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 
>> rubyonra...@googlegroups.com
>> .
>> To unsubscribe from this group, send email to 
>> rubyonrails-ta...@googlegroups.com .
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msg/rubyonrails-talk/-/3xoM8jq4ED8J.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>  
>>  
>>
>
>
>
> -- 
> -
> visit my blog at http://jimlabs.heroku.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.
To view this discussion on the web visit 
https://groups.google.com/d/msg/rubyonrails-talk/-/Y2teFjkW-McJ.
For more options, visit https://groups.google.com/groups/opt_out.




[Rails] Sunspot Solr specialized search

2012-11-21 Thread Keith Raymond
Hello all,

I have a question that I've searched for a bit but can't really find
anything. I might not be searching on the right things.

I have Sunspot/solr working great and now I want to start using it to
speed up Backbone.js queries. I have it currently working with straight
Rails.

==
CONTROLLER
  def members
@group = Group.find(params[:group_id])
@members = @group.members.nil? ? nil : @group.members.reject {
|user| !user.active? }
respond_with(@members.to_json
  end

MODEL (Group)
  def members
@members ||= roles.members.collect { |role| role.user }.compact
unless roles.members.empty?
  end
==

Basically I'm trying to figure out a way to return :members method's
results more quickly.   I know with sunspot/solr you can index methods,
but this helps with searching on a member get getting the group.  I
basically need the opposite.

What makes this more complicated is that Group has_many :users, :through
=> :roles as a polymorphic relationship.

Roles table
===
user_id  => user's id
object_type   => object for (Group, Forum, etc)
object_id   => id of object (Group, Forum, etc)
===

I know its complicated but it really needs to be this way.  If anyone
has any ideas I would greatly appreciate it.

Thanks

-- 
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 https://groups.google.com/groups/opt_out.




Re: [Rails] is there a better DRY code writing for this scope ?

2012-11-21 Thread Jim Ruther Nill
On Wed, Nov 21, 2012 at 9:33 PM, Erwin  wrote:

> I wrote this scope in my Subdomain model :
>
>   scope :in_account, lambda { |account_id|
> if account_id == "*"
>   where("account_id >= ?", 0)
> else
>   where(account_id: account_id)
> end
>   }
>
> where account_id == '*'  then all subdomain instances are selected
> when account_id is given , only subdomain instances in this account are
> selected
>
> is there a better writing ?
>

you can use scoped instead

account_id == '*' ? scoped : where(account_id: account_id)


>
> thanks for feedback
>
>  --
> 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.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/rubyonrails-talk/-/3xoM8jq4ED8J.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>



-- 
-
visit my blog at http://jimlabs.heroku.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 https://groups.google.com/groups/opt_out.




[Rails] is there a better DRY code writing for this scope ?

2012-11-21 Thread Erwin
I wrote this scope in my Subdomain model :

  scope :in_account, lambda { |account_id|
if account_id == "*"
  where("account_id >= ?", 0)
else
  where(account_id: account_id) 
end
  }

where account_id == '*'  then all subdomain instances are selected
when account_id is given , only subdomain instances in this account are 
selected

is there a better writing ?

thanks for feedback

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msg/rubyonrails-talk/-/3xoM8jq4ED8J.
For more options, visit https://groups.google.com/groups/opt_out.




[Rails] Are Rail's database tools really helpful?

2012-11-21 Thread Denis BEURIVE
Hello,

I am looking at Rails for two days. I already use ZF (Zend Framework),
Codeigniter and ELGG.

My big concern is the ORM's.

In a real world application, you don't just play with one table at a
time. You have to write long SQL requests, with several tables : Using
ZF (Zend Framework) ou Codeigniter, I realized that the batabase layer
becomes a real pain in the ass.

Instead of writing a simple SQL request, you write a complicated set of
methods' invocations (with options...).

The resulting code is not easy to read. You think : I should write an
easy to read SQL request!

Some says : yes, but by using the database abstraction, you can change
you database easily (ex : from MySql to SQLServer)!

OK, but... Did you ever change your database ?

If you really need to migrate from MySql to SQLServer, then it means
that you have a *deep* problem. You may need to restructure your
database...

And what about "migrations" ?

Migrations keep track of structure's changes. OK, but why don't you just
keep your database's schema under SVN (or Git) ?

Migrations can be used to change the database's content. OK, but
everything is not reversible. And, by the way, you should always work on
the testing environment.

So, my question is :

Do you really use all the Rails' tools to manage your database ?

Can you use Rails without Active Record ?

Thanks,

Denis

-- 
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 https://groups.google.com/groups/opt_out.




[Rails] What to use //= require_tree or js,css incude tag in application.erb ?

2012-11-21 Thread Fahim Patel
Hi ,

We are using reqiure_tree in our application.js and application.css.
As per i know  require_tree include all js and css in application.js and 
application.css .

 We include application file of both .js and .css in our application.erb.

Q .  We include both .js and .css application file in application.erb .
   Is  including in application.erb, did all .js and .css file are 
included in application.erb or not ?
 
  If yes , than why we include each .js and .css one more time in 
application.erb ?

Example
Assume that i make myjs.js and mycss.css and put them respectively in asset 
folder.

##application.erb##
   <%= stylesheet_link_tag"application", :media => "all" %>
<%= stylesheet_link_tag "mycss"  %># is i have to include it here or above 
line  is enough for me because we have use require_tree in application.css 
and which include all .css in application.css

<%= javascript_include_tag "application" %>
<%= javascript_include_tag "myjs" %># is i have to include it here or above 
line  is enough for me because we have use require_tree in application.js 
and which include all .js in application.js.


I am confused .

Hope you will understood the situation .

Thanks
Fahim Babar Patel

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msg/rubyonrails-talk/-/qlFHEVOolpgJ.
For more options, visit https://groups.google.com/groups/opt_out.




[Rails] Re: Share Cookies in rails 3.1.3

2012-11-21 Thread kingston.s

i got the error.Its working now. Its my mistake.

On Tuesday, November 20, 2012 5:38:45 PM UTC+5:30, kingston.s wrote:
>
> Hi all,
>
>
>   i am using Rails 3.1.3 and ruby 1.9.3.i need to set the cookies for 
> multiple domain,
>  Example: *test.abc.com* and *example.abc.com* are the two 
> different domain, i need to set the same cookie for the both domain. If 
> user login with *test.abc.com* can automatically login with *
> example.abc.com*..
>
> I have tried :
> Rails.application.config.session_store :cookie_store, :key => 
> '_Admin_Kernel_session', :domain=>:all
> Rails.application.config.session_store :cookie_store, :key => 
> '_Admin_Kernel_session', :domain=>".abc.com"
> cookies.permanent.signed[:new_cookie] = {:value => new_value, 
> :domain => ".abc.com"}
> cookies[:some_cookie] = {:value => "whatever", :domain => ".
> abc.com", :expires => 1.year.from_now.utc}
>  
> i have tested with  middle-ware to set session domain but no 
> use.
>
> Please could any one tell me how to implement.
>
> Kingston.s
>
>
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msg/rubyonrails-talk/-/nmYlPnvWs-QJ.
For more options, visit https://groups.google.com/groups/opt_out.




[Rails] Re: Rails 3.2 Extending String Core Classe as per Rails doc

2012-11-21 Thread Erwin
Thanks Fred for this clear feedback ...
I did it  (added require 'yoodle.rb'  in my  initializers/configuration.rb) 
 and it works ...

:-)))

Le mercredi 21 novembre 2012 00:18:43 UTC+1, Frederick Cheung a écrit :
>
>
> On Tuesday, November 20, 2012 4:46:56 PM UTC, Erwin wrote:
>>
>>
>> and I have added in yoodle/config/application.rb
>> config.autoload_paths += Dir["#{config.root}/lib", 
>> "#{config.root}/lib/**/"]
>>
>> but running in console
>> > "AAA".to_squawk   raises an error
>> NoMethodError: undefined method `to_squawk' for "AAA":String
>>
>>
>>
> autoload_paths is the set of paths that can be autoloaded - they won't 
> actually be loaded on startup in development mode (although they would be 
> in production).
>
> The example in the doc is written from the point of view of writing the 
> extension as part of a gem, in wich case lib/yaffle gets loaded for you by 
> bundler. You seem to be adding this straight to your app, so you don't get 
> this behaviour. The simplest thing is probably to add an initializer that 
> requires yoodle.rb for you 
>
> Fred
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msg/rubyonrails-talk/-/cA_CP7G50Z8J.
For more options, visit https://groups.google.com/groups/opt_out.