rubyonrailsin

A Ruby and Rails talk

Recent Post

Friday, April 2, 2010

[Rails] Re: App_Controller and partial issues with has_many through

by rubyonrailsin 0 comments
When inspecting it I get [#,#,#,#] and my title reads "Your Interests
(4)" and the print out is
#
#
#
#

What is # all about? Is that an object filled with objects?


Colin Law wrote:
> On 2 April 2010 15:07, Jason Newport <lists@ruby-forum.com> wrote:
>> class ApplicationController < ActionController::Base
>> �end
>> � �<% @user_interests.each do |interest| -%>
>>
>> seems to be counting the number of posts on the specific pages (index or
>> show) and totaling those up as a users interests. �And if for one user I
>> add two interests and view the single post page then the title will read
>> "You have 3 interests", thus counts the two interests I really am
>> interested in plus the one for the Post page I am even though I have yet
>> to click/select it as an interest.
>
> I would suggest installing ruby-debug, then you can break into the
> controller or the view and inspect the variables and work out what is
> going wrong.
>
> See the rails guide on debugging at http://guides.rubyonrails.org/
>
> Colin

--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Read More…

[Rails] Re: Need help with find

by rubyonrailsin 0 comments
Finally figured out something that worked.

@club = Club.find(params[:club_id])
ids = @club.members.connection.select_values('SELECT person_id FROM
members')
@people = Person.all(:order => 'name_sort',
:conditions => ["id NOT IN (?)",
ids])

Any comments or better methods.

--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Read More…

[Rails] GurusQ: Metal calling disparity-How to install metal in code

by rubyonrailsin 0 comments
I have a simple class that I want to install as Rails Metal. I don't
want to put it into a file in app/metal for reasons I don't want to go
into. It looks like this, and handler is defined elsewhere.

class UrlFilter
ALLOW = [404]
DENY = [403]
def self.call(env)
handler.call(env["PATH_INFO"]) ? ALLOW : DENY
end
end

I've tried installing it like this :
ActionController::Dispatcher.middleware.use UrlFilter

but on the first request it crashes with :

Sat Apr 03 00:29:43 +0800 2010: Read error: #<ArgumentError: wrong
number of arguments (0 for 1)>
/Library/Ruby/Gems/1.8/gems/actionpack-2.3.5/lib/action_controller/middleware_stack.rb:31:in
`call'
/Library/Ruby/Gems/1.8/gems/actionpack-2.3.5/lib/action_controller/middleware_stack.rb:31:in
`klass'
/Library/Ruby/Gems/1.8/gems/actionpack-2.3.5/lib/action_controller/middleware_stack.rb:42:in
`active?'
/Library/Ruby/Gems/1.8/gems/actionpack-2.3.5/lib/action_controller/middleware_stack.rb:112:in
`active'
/Library/Ruby/Gems/1.8/gems/actionpack-2.3.5/lib/action_controller/dispatcher.rb:108:in
`find_all'
/Library/Ruby/Gems/1.8/gems/actionpack-2.3.5/lib/action_controller/middleware_stack.rb:112:in
`each'
/Library/Ruby/Gems/1.8/gems/actionpack-2.3.5/lib/action_controller/middleware_stack.rb:112:in
`find_all'
/Library/Ruby/Gems/1.8/gems/actionpack-2.3.5/lib/action_controller/middleware_stack.rb:112:in
`active'
/Library/Ruby/Gems/1.8/gems/actionpack-2.3.5/lib/action_controller/middleware_stack.rb:116:in
`build'
/Library/Ruby/Gems/1.8/gems/actionpack-2.3.5/lib/action_controller/dispatcher.rb:130:in
`build_middleware_stack'
/Library/Ruby/Gems/1.8/gems/actionpack-2.3.5/lib/action_controller/dispatcher.rb:113:in
`call'
/Library/Ruby/Gems/1.8/gems/actionpack-2.3.5/lib/action_controller/reloader.rb:34:in
`run'
/Library/Ruby/Gems/1.8/gems/actionpack-2.3.5/lib/action_controller/dispatcher.rb:108:in
`call'
/Library/Ruby/Gems/1.8/gems/rails-2.3.5/lib/rails/rack/static.rb:31:in
`call'
/Library/Ruby/Gems/1.8/gems/rack-1.0.1/lib/rack/urlmap.rb:46:in `call'
/Library/Ruby/Gems/1.8/gems/rack-1.0.1/lib/rack/urlmap.rb:40:in `each'
/Library/Ruby/Gems/1.8/gems/rack-1.0.1/lib/rack/urlmap.rb:40:in `call'
/Library/Ruby/Gems/1.8/gems/rails-2.3.5/lib/rails/rack/log_tailer.rb:17:in
`call'
/Library/Ruby/Gems/1.8/gems/rack-1.0.1/lib/rack/content_length.rb:13:in
`call'
/Library/Ruby/Gems/1.8/gems/rack-1.0.1/lib/rack/chunked.rb:15:in `call'
/Library/Ruby/Gems/1.8/gems/rack-1.0.1/lib/rack/handler/mongrel.rb:64:in
`process'
/Library/Ruby/Gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:159:in
`process_client'
/Library/Ruby/Gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:158:in `each'
/Library/Ruby/Gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:158:in
`process_client'
/Library/Ruby/Gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:285:in `run'
/Library/Ruby/Gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:285:in
`initialize'
/Library/Ruby/Gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:285:in `new'
/Library/Ruby/Gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:285:in `run'
/Library/Ruby/Gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:268:in
`initialize'
/Library/Ruby/Gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:268:in `new'
/Library/Ruby/Gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:268:in `run'
/Library/Ruby/Gems/1.8/gems/rack-1.0.1/lib/rack/handler/mongrel.rb:34:in
`run'
/Library/Ruby/Gems/1.8/gems/rails-2.3.5/lib/commands/server.rb:111
/Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in
`gem_original_require'
/Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `require'
script/server:3

The rails calling code looks like this :

def klass
if @klass.respond_to?(:call)
@klass.call
elsif @klass.is_a?(Class)
@klass
else
@klass.to_s.constantize
end
rescue NameError
@klass
end

def active?
return false unless klass

if @conditional.respond_to?(:call)
@conditional.call
else
@conditional
end
end

Notice when calling call no arguments are passed (twice!) ? Every metal
example I've seen defines the entry method as

def self.call(env)

yet this calling code doesn't pass any.

Whats going on ? How do I define and install a metal class in code ?
--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Read More…

[Rails] Re: Rails cascading delete

by rubyonrailsin 0 comments
Thanks all. Destroy worked great!,

Thanks
Hila;


On Apr 2, 2:41 am, Lasse Bunk <lasseb...@gmail.com> wrote:
> Hi Hilal,
>
> You need to use :dependent => :destroy instead of :delete_all because
> :delete_all doesn't fire any callbacks. That's why it only deletes one
> level.
>
> /Lasse
>
> 2010/4/2 Hilal <hilal.sha...@gmail.com>
>
> > Hello There:
> >    I am trying to do a deep cascading deletes in rails.
>
> > The schema looks like this:
>
> > Blogs (has many) entries ( has many ) comments
>
> > A blog has n entries, an entry has n comments.
>
> > So, in my Blog model I use
> > has_many :entries, :dependent => :delete_all
> > and in my Entry model I use
> > has_many :comments,:dependent => :delete_all
>
> >   The problem I am having is that deleting blogs, will only delete
> > entries, but will not delete comments. In other words, the cascading
> > delete isn't deep?
>
> >   Am I doing something wrong here?
>
> > Thanks
> > Hilal
>
> > --
> > 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+unsubscribe@googlegroups.com<rubyonrails-talk%2Bunsubscribe@googlegroups.com>
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/rubyonrails-talk?hl=en.

--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Read More…

[Rails] Using Builders

by rubyonrailsin 0 comments
I am using RoR 2.3, and have installed the builder gem

I have a line in a view as follows:

str_xml = render "fusioncharts/array_example/ss_array_data.builder",
{:arr_data => @arr_data}

Which does not set str_xml to anything.

I can confirm that in my controller I have @arr_data set up and
populated properly. (And in my controller, I have require 'builder'
at the top)

In my views folder, I have a folder set up under it as "fusioncharts/
array_example/" and the file ss_array_data.builder. (However, this may
be why str_xml is not being set -- when I go to the URL which would
invoke this view, I get "Missing template _ss_array_data.builder in
view path..." It will only render the page if I put the underscore
before the filename ss_array_data.builder, making it a partial).

What am I not understanding about builders that I cannot convert my
array @arr_data to str_xml ?

Thanks so much, RVince

--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Read More…

Re: [spree-user] Re: User Personalisation of Products

by rubyonrailsin 0 comments
A quick browse through your code shows that you can set options for a
product, but where were you planning on storing the information from
the user? I don't see any changes to the line_items table (or a
separate table), etc to store the personalization input from the user.

It also appears that each product can only have a single
personalization option. Is this your goal?

I have the need for something similar, but I need multiple
personalization options per product, and it needs to support more
options than a single text field (some "personalization" needs to be
radio buttons, select boxes, etc).

I would also merge your migrations right now while nobody is really
using the code. The way your migrations are currently written, if
someone was using a version that used the :personalisation_options
column inside products or variants, those changes would be lost when
you ran the 20100320220929_add_personalisable.rb migration since you
don't alter the name of the column, you drop it then re-create it. Of
course during the drop you lose any data that was entered by the admin
in that column. I assume that you are making the assumption that
nobody is using that previous version so it is ok to make the drop,
but if that's the case then you may as well clean up the migrations to
create the proper column to begin with. (Just my $0.02 on the
migrations)

-Chris

On Sat, Apr 3, 2010 at 6:24 AM, peachygifts <m.ward@leythers.com> wrote:
> The admin side of my extension is now working: an admin can set a
> product to be personalisable, and can then set personalisation options
> against a product.
>
> Now I would like to display these results of these options to
> customers:
>
> The product has a personalisable? attribute. The product may also have
> many personalisation_options associated with it. Each
> personalisation_option has name, title and max_length
>
> Step 1 now has me a little flummoxed: I need to build fields on the
> product page for each personalisation_option associated with a
> product, rendered as a label with title as its contents, and a text
> field that limits to the number of character specified in max_length.
>
> How do I go about this in spree / rails?
>
> For anyone interested in helping, the current extension can be found
> in its current gestation at git://github.com/peachygifts/spree-personalisation.git
>
> Thanks for your help!
>
> Michael
>
> --
> You received this message because you are subscribed to the Google Groups "Spree" group.
> To post to this group, send email to spree-user@googlegroups.com.
> To unsubscribe from this group, send email to spree-user+unsubscribe@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/spree-user?hl=en.
>
>

--
You received this message because you are subscribed to the Google Groups "Spree" group.
To post to this group, send email to spree-user@googlegroups.com.
To unsubscribe from this group, send email to spree-user+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/spree-user?hl=en.

Read More…

[Rails] Re: Best way of sorting/grouping objects

by rubyonrailsin 0 comments
By any chance do you have a model named PageType? If you, you could
set up a relationship between PageType and Page:

page.rb:
belongs_to :page_type

page_type.rb:
has_many :pages

Then display it with:

your_controller.rb:
@page_types = PageType.all

your_view.html.haml (or .erb, etc.)
- @page_types.each do |page_type|
%h1= page_type.name
%ul
= list_of page_type.pages do |page|
= page.name

If you don't already have a PageType model, or don't want to introduce
another model, you could probably use:

@page_types = Page.all(:order => 'page_type', :group => 'page_type')

and then play around with the result of that. (At least I think that's
correct… haha, sorry if it's not)

Good luck,
Angelo

On Apr 2, 7:31 am, Brent <wejrow...@gmail.com> wrote:
> That could work. But I need it to order by page_order also.  I would
> like to group them into 3 groups then sort them by that. In the end I
> want it to look something like this in html...
>
> TYPE ONE
> Page 1
> Page 2
>
> TYPE TWO
> Page 1
> Page 2
>
> Before I was doing something like this (I had an array of each page
> type called page_types):
>
> <% page_types.each do |t| %>
>     <%= t %>'s
>    <% Page.find(:all, :conditions=>{:page_type=>t}, :order=>position
> %>
>      etc.
>   <% end %>
> <% end %>

--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Read More…

Subscribe feeds via e-mail

Blog Archive