All,

I have numerous places in my codebase like this:

redirect_to :action => 'schedule_by_uid_and_run_date', :uid =>
@schedule.first.train_uid, :year => @date.year, :month => @date.month,
:day => @date.day

I'd like to replace the :year, :month and :day parameters with a hash
containing the three parameters. @date is an instance of a Date class,
and the trouble with that is Date.month is a single character. I'd like
it to be null-padded, but it seems messy to put .rjust(2, '0') against
all three parameters everywhere in the code.

Is it possible to do something like this?

redirect_to :action => 'foo', :uid => @schedule.first.train_uid,
params_hash

...where params_hash contains { :year => '2011', :month => '01', :day =>
'19' }

Cheers,


Peter


--
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.

Search Discussions

  • Ahmy Yulrizka at Jan 20, 2012 at 9:22 am
    http://apidock.com/rails/ActionController/Redirecting/redirect_to assuming
    you use rails 3.1

    this might work :

    redirect_to {:action => 'foo', :uid => @schedule.first.train_uid,
    params_hash}.merge(param_hash)

    Ahmy Yulrizka

    On Fri, Jan 20, 2012 at 5:41 AM, Peter Hicks wrote:

    redirect_to
    --
    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.
  • Ahmy Yulrizka at Jan 20, 2012 at 9:22 am
    sorry redirect_to {:action => 'foo', :uid =>
    @schedule.first.train_uid}.merge(param_hash)

    Ahmy Yulrizka

    On Fri, Jan 20, 2012 at 4:21 PM, Ahmy Yulrizka wrote:

    params_hash
    --
    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.
  • Peter Hicks at Jan 20, 2012 at 9:27 am

    On Fri, Jan 20, 2012 at 04:22:14PM +0700, Ahmy Yulrizka wrote:

    sorry redirect_to {:action => 'foo', :uid => @schedule.first.train_uid}.merge(param_hash)
    I think I tried that already, but I'll give it a go.

    I settled on...

    redirect_to :action => 'foo', :uid => ..., nil => param_hash

    ...but I'm not sure if it feels horribly dirty or elegantly smart.


    Peter

    --
    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.
  • Bala TS at Jan 20, 2012 at 10:45 am
    Hai:

    # create virtual models
    # year_entry.rb

    attr_accessor :year,
    :month,
    :day

    # controller:

    @year_entry_access = []
    year_var = YearEntry.new
    year_var.year = 2012
    year_var.month = 1
    year_var.day = 20
    @year_entry_access << year_var

    redirect_to :action=>show_rrr,:year_entry_access =>@year_entry_access


    # After that you can pass other method

    def show_rrr
    if params[:year_entry_access] # here you can get params_hash format
    params[:year_entry_access].each_value do |get_date|
    get_date[:date]
    get_month[:month]
    get_year[:year]
    end
    end
    end

    # you can access like this way "get_date[:date]"

    Bye:)
    bdeveloper

    --
    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.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouprubyonrails-talk @
categoriesrubyonrails
postedJan 19, '12 at 10:41p
activeJan 20, '12 at 10:45a
posts5
users3
websiterubyonrails.org
irc#RubyOnRails

People

Translate

site design / logo © 2022 Grokbase