Becca Girl | 16 May 00:15
Gravatar

help needed with where and how best to set a param


Once again, I'm writing about a pop-up window issue and need some help.
Trying to insert a new record prior to the pop-up and other sorts of
things has proven to be a much bigger problem so instead I'll have a
default record that will serve as a placeholder for new pop-up window
values.

In my main form, if I'm editing an order, the order id is sent to the
pop-up window.  Then my pop-up window uses that information.  If it's a
new order, the pop-up window doesn't have an order id.

To work around this, I'd like to set a default order ID that I'll use
for new orders so that the pop-up window options work.

My link to the pop-up looks like this:

<%= link_to 'small window',{ :controller => 'codes', :action =>
'pop_up',
:id => @order},  :popup => ['codes',
'width=450,height=600,menubar=no,resizable=yes,scrollbars=yes'] %>

How can I override :id => @order so that I send in a default ID of 1?

If anyone has other, better design ideas, I'd love to hear them.  I
think I've exhausted all of the ones that I have seen.
--

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

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
(Continue reading)

AndyV | 16 May 20:42
Picon

Re: help needed with where and how best to set a param


Have you tried making this special route a :collection route instead
of a :member route?

If it were a collection route then the :id would be optional... but it
might also solve the bigger problem more gracefully.  In your popup
action you could have something like this:

@order = params[:id].nil? ? Order.new : Order.find_by_id(params[:id])

Then your view could build the url either for insert (new_record?) or
update.  If you're already taking advantage of the new Rails 'form_for
@ivar' then it should be done for you.

HTH,
AndyV

On May 15, 6:16 pm, Becca Girl <rails-mailing-l...@...>
wrote:
> Once again, I'm writing about a pop-up window issue and need some help.
> Trying to insert a new record prior to the pop-up and other sorts of
> things has proven to be a much bigger problem so instead I'll have a
> default record that will serve as a placeholder for new pop-up window
> values.
>
> In my main form, if I'm editing an order, the order id is sent to the
> pop-up window.  Then my pop-up window uses that information.  If it's a
> new order, the pop-up window doesn't have an order id.
>
> To work around this, I'd like to set a default order ID that I'll use
(Continue reading)

Becca Girl | 16 May 22:11
Gravatar

Re: help needed with where and how best to set a param


AndyV wrote:
> Have you tried making this special route a :collection route instead
> of a :member route?
> 
> If it were a collection route then the :id would be optional... but it
> might also solve the bigger problem more gracefully.  In your popup
> action you could have something like this:
> 
> @order = params[:id].nil? ? Order.new : Order.find_by_id(params[:id])
> 
> Then your view could build the url either for insert (new_record?) or
> update.  If you're already taking advantage of the new Rails 'form_for
> @ivar' then it should be done for you.
> 

I will definitely try the route.  Right now I'm using the DRY Forms 
example in the new Advanced Rails Recipes book so I'd like to avoid 
converting the forms back, but I may need to do that anyway to denote 
required fields.

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@...
To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@...
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en
(Continue reading)

AndyV | 17 May 22:28
Picon

Re: help needed with where and how best to set a param


The DRY form recipe extends the FormBuilder so you'll get all the
freebies that the FormBuilder is already providing -- like the ability
to tell if you've got a new object to create or an existing object to
update.  If you follow the logic presented in the recipe you should be
able to extend it to denote required fields, too.  You should be able
to provide a 'required' attribute in a similar way they provide the
override for the label.

HTH,
AndyV

On May 16, 4:11 pm, Becca Girl <rails-mailing-l...@...>
wrote:
> AndyV wrote:
> > Have you tried making this special route a :collection route instead
> > of a :member route?
>
> > If it were a collection route then the :id would be optional... but it
> > might also solve the bigger problem more gracefully.  In your popup
> > action you could have something like this:
>
> > @order = params[:id].nil? ? Order.new : Order.find_by_id(params[:id])
>
> > Then your view could build the url either for insert (new_record?) or
> > update.  If you're already taking advantage of the new Rails 'form_for
> > @ivar' then it should be done for you.
>
> I will definitely try the route.  Right now I'm using the DRY Forms
> example in the new Advanced Rails Recipes book so I'd like to avoid
(Continue reading)

Becca Girl | 20 May 22:11
Gravatar

Re: help needed with where and how best to set a param


AndyV wrote:
 If you follow the logic presented in the recipe you should be
> able to extend it to denote required fields, too.  You should be able
> to provide a 'required' attribute in a similar way they provide the
> override for the label.

I'm still learning my way around RoR.  I see this in the DRY Forms 
helper code:

    @template.capture do
      locals = {
        :element => yield,
        :label   => label(field, options[:label])
      }

Would I add something there to designate that I need the required fields 
to look a little different?

Here's the form field template and how it's displayed:
  <span class="label">
    <%= label %>
  </span>

So if it's required, I want to add a red asterisk.

Thanks for helping a newbie.
--

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

(Continue reading)

AndyV | 21 May 03:17
Picon

Re: help needed with where and how best to set a param


Yes, you're in the right ballpark.  There are a few different ways you
could go.

First, I'd recommend that you piggyback on that 'option' hash.  I'd
probably use a value like 'required_field' or something like that.
From that point you have the options.  One way to approach it would be
to use option[:required_field] to add a css class to the field.

    @template.capture do
      locals = {
        :element => yield,
        :label   => label(field, options[:label], :class=>
options[:required_field] ? 'required' : 'label')
      }

Another option would be to just add a '*' to the label.  Right before
the call to 'build_shell':

options[:label] ||= field.to_s.humanize # default value for label if
none was provide
options[:label] << " *" if options[:required_field] # Add asterisk if
requred

On May 20, 4:11 pm, Becca Girl <rails-mailing-l...@...>
wrote:
> AndyV wrote:
>
>  If you follow the logic presented in the recipe you should be
>
(Continue reading)

Becca Girl | 23 May 23:33
Gravatar

Re: help needed with where and how best to set a param


AndyV wrote:

> @order = params[:id].nil? ? Order.new : Order.find_by_id(params[:id])
> 

I'm working on this with many other projects so I'm slow to getting the 
code in to test.

I implemented the above code, but here's where the other gotcha comes in 
when I have a new order.  Right now in my drag and drop, I've got a div 
that displays all of the selected items.  When I drag items there now, 
it replaces whatever I have previously selected with the new dragged 
item.  Now I know this is due to how I have it set up.  I've got the 
partials and controllers hitting the database each time an item is 
selected.  I save the value in the order and then call it back to show 
the selected items.

It seems to me that I'm going to need to create a persistent variable 
that will contain the string of values of the item id's.  But the other 
gotcha in this is that when an item is selected, it is removed from the 
list of available options.  This makes it more user friendly so someone 
can see what they've chosen.

Any thoughts on this one?  Again, this works great when I'm editing a 
record because I can save to the existing order, not so great with new 
orders.

THANKS!!!
--

-- 
(Continue reading)

Becca Girl | 27 May 18:09
Gravatar

Re: help needed with where and how best to set a param


Becca Girl wrote:

> Any thoughts on this one?  Again, this works great when I'm editing a 
> record because I can save to the existing order, not so great with new 
> orders.
> 

Just thought I'd bump this given that the US had a holiday weekend.  Any 
thoughts?  Please see previous post for details.

--

-- 
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@...
To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@...
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---


Gmane