Hi folks,
I am trying to hack in_place_edit_for to avoid empty fields:
def in_place_edit_for(object, attribute, options = {})
if params[:value] == ''''
params[:value] = ''Hey! You must fill the field!''
end
super(object,attribute,options)
end
It doesn''t work, the params[:value] is not affected.
But I''ve done the same thing with the in_place_editor helper to
globalize options[] parameters and it works...
(ok, I could past the 3 lines of define_method...)
--
,========================.
| Pierre-Alexandre Meyer |
| email : pam-1sEOgp2Wo8Qdnm+yROfE0A@public.gmane.org |
`========================''
--~--~---------~--~----~------------~-------~--~----~
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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Are you sure params[:value] is actually an empty string? I''d shorten that to params[:value] = "Hey! You must fill the field!" if params[:value].blank? or, to avoid a string of spaces [correctly] validating as !blank?, params[:value] = "Hey! You must fill the field!" if params[:value].strip.blank? RSL On 3/15/07, Pierre-Alexandre Meyer <pam-1sEOgp2Wo8Qdnm+yROfE0A@public.gmane.org> wrote:> > > Hi folks, > > I am trying to hack in_place_edit_for to avoid empty fields: > > def in_place_edit_for(object, attribute, options = {}) > if params[:value] == '''' > params[:value] = ''Hey! You must fill the field!'' > end > super(object,attribute,options) > end > > > It doesn''t work, the params[:value] is not affected. > > But I''ve done the same thing with the in_place_editor helper to > globalize options[] parameters and it works... > > (ok, I could past the 3 lines of define_method...) > > -- > ,========================. > | Pierre-Alexandre Meyer | > | email : pam-1sEOgp2Wo8Qdnm+yROfE0A@public.gmane.org | > `========================'' > > > > >--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Thu, Mar 15, 2007 at 10:17:19AM -0400, Russell Norris wrote :> Are you sure params[:value] is actually an empty string?params hash is: {"action"=>"set_user_mail", "id"=>"3", "value"=>"", "controller"=>"my_bug_app"}> I''d shorten that to > > params[:value] = "Hey! You must fill the field!" if params[:value].blank? > > or, to avoid a string of spaces [correctly] validating as !blank?, > > params[:value] = "Hey! You must fill the field!" if > params[:value].strip.blank?You''re right, it''s cleaner :) Anyway, it doesn''t work either :''( -- ,========================. | Pierre-Alexandre Meyer | | email : pam-1sEOgp2Wo8Qdnm+yROfE0A@public.gmane.org | `========================'' --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Well, it was worth a try. :) I''ve never used in_place_editor so I really don''t know much about it. I was going to look at the API but its [gasp!] down. [again.] RSL On 3/15/07, Pierre-Alexandre Meyer <pam-1sEOgp2Wo8Qdnm+yROfE0A@public.gmane.org> wrote:> > > On Thu, Mar 15, 2007 at 10:17:19AM -0400, Russell Norris wrote : > > Are you sure params[:value] is actually an empty string? > > params hash is: > {"action"=>"set_user_mail", "id"=>"3", "value"=>"", > "controller"=>"my_bug_app"} > > > I''d shorten that to > > > > params[:value] = "Hey! You must fill the field!" if > params[:value].blank? > > > > or, to avoid a string of spaces [correctly] validating as !blank?, > > > > params[:value] = "Hey! You must fill the field!" if > > params[:value].strip.blank? > > You''re right, it''s cleaner :) Anyway, it doesn''t work either :''( > > -- > ,========================. > | Pierre-Alexandre Meyer | > | email : pam-1sEOgp2Wo8Qdnm+yROfE0A@public.gmane.org | > `========================'' > > > > >--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
The reason it''s not work is because in_place_edit_for defines an
instance method which will access params at run-time. Not define
time. So the statement you put before super will have no effect.
23: def in_place_edit_for(object, attribute, options = {})
24: define_method("set_#{object}_#{attribute}") do
25: @item object.to_s.camelize.constantize.find(params[:id])
26: @item.update_attribute(attribute, params[:value])
27: render :text => @item.send(attribute)
28: end
29: end
You should monkey patch this method or you can simply define the
action it would have defined yourself.
For some reason it has an options parameter but never uses it... so
your patch could be flexible.
e.g.
in_place_edit_for(:post, :comment, :check_blanks => true, :blank_error
=> ''What do you want to say?'')
---
module ActionController
module Macros
module InPlaceEditing
module ClassMethods
def in_place_edit_for(object, attribute, options = {})
define_method("set_#{object}_#{attribute}") do
@item = object.to_s.camelize.constantize.find(params[:id])
if params[:value].blank? && options[:check_blanks]
render :text => options[:blank_error] || "Fill in this
field."
else
@item.update_attribute(attribute, params[:value])
render :text => @item.send(attribute)
end
end
end
end
end
end
end
On Mar 15, 7:54 pm, Pierre-Alexandre Meyer
<p...-1sEOgp2Wo8Qdnm+yROfE0A@public.gmane.org>
wrote:> Hi folks,
>
> I am trying to hack in_place_edit_for to avoid empty fields:
>
> def in_place_edit_for(object, attribute, options = {})
> if params[:value] == ''''
> params[:value] = ''Hey! You must fill the field!''
> end
> super(object,attribute,options)
> end
>
> It doesn''t work, the params[:value] is not affected.
>
> But I''ve done the same thing with the in_place_editor helper to
> globalize options[] parameters and it works...
>
> (ok, I could past the 3 lines of define_method...)
>
> --
> ,========================.
> | Pierre-Alexandre Meyer |
> | email : p...-1sEOgp2Wo8Qdnm+yROfE0A@public.gmane.org |
> `========================''
--~--~---------~--~----~------------~-------~--~----~
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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
On Fri, Mar 16, 2007 at 03:05:52AM -0000, eden li wrote :> The reason it''s not work is because in_place_edit_for defines an > instance method which will access params at run-time. Not define > time. So the statement you put before super will have no effect.Gasp! You''re right. I''m so stupid.> in_place_edit_for(:post, :comment, :check_blanks => true, :blank_error > => ''What do you want to say?'') > > module ActionController > module Macros > module InPlaceEditing > module ClassMethods > def in_place_edit_for(object, attribute, options = {}) > define_method("set_#{object}_#{attribute}") do > @item = object.to_s.camelize.constantize.find(params[:id]) > if params[:value].blank? && options[:check_blanks] > render :text => options[:blank_error] || "Fill in this > field." > else > @item.update_attribute(attribute, params[:value]) > render :text => @item.send(attribute) > end > end > end > end > end > end > endNice solution :) Thanks. -- ,========================. | Pierre-Alexandre Meyer | | email : pam-1sEOgp2Wo8Qdnm+yROfE0A@public.gmane.org | `========================'' --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---