https://gist.github.com/1644085

#verifications/index.haml
- if Ad.unverified_ads.size == 0
- else
= link_to "Fast Verify",
fast_verify_info_verification_path(Ad.unverified_ads.last), :method =>
:put
= link_to "Normal Verify", verify_info_verification_path(ad), :method =>
:put

#verifications/verify_info.haml
= link_to "Verify", verify_verification_path(@ad)

#verifications/fast_verify_info.haml
= link_to "Verify",
fast_verify_verification_path(Ad.unverified_ads.last), :method => :put

#verification_controller.rb
def verify_info
@ad = Ad.find(params[:id])
end

def fast_verify_info
@ad = Ad.find(params[:id])
end

def fast_verify
@ad = Ad.find(params[:id])
@ad.verify!
if Ad.unverified_ads.size == 0
redirect_to verifications_path
else
redirect_to
fast_verify_info_verification_path(Ad.unverified_ads.last)
end
end

def verify
@ad = Ad.find(params[:id])
@ad.verify!
if params[:fast] == true
redirect_to Ad.unverified_ads.last
else
redirect_to verifications_path
end
end

I think there is too many actions, how to improve this?

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

Search Discussions

  • Michael Pavling at Jan 20, 2012 at 2:23 pm
    Try replacing the redundant bits one at a time. For instance:

    Ad.unverified_ads.size == 0
    is equivalent to
    Ad.unverified_ads.blank?

    And you're repeating "if...else" a lot with just one line in each, so
    turn it into a ternary:

    if Ad.unverified_ads.size == 0
    redirect_to verifications_path
    else
    redirect_to fast_verify_info_verification_path(Ad.unverified_ads.last)
    end

    becomes

    redirect_to (Ad.unverified_ads.blank? ? verifications_path :
    fast_verify_info_verification_path(Ad.unverified_ads.last))

    --
    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.
  • Regedarek at Jan 22, 2012 at 12:59 pm
    Thanks a lot, this my amendments.
    https://gist.github.com/1643261

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/9nw3zUSoK50J.
    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.
  • Darek F. at Jan 20, 2012 at 10:21 pm
    Thanks a lot.

    I maked some improvments =>

    #verifications/index.haml
    - if Ad.unverified_ads.size == 0
    - else
    = link_to "Fast Verify",
    fast_verify_info_verification_path(Ad.unverified_ads.last), :method =>
    :put
    = link_to "Normal Verify", verify_info_verification_path(ad), :method =>
    :put

    #verifications/verify_info.haml
    = link_to "Verify", verify_verification_path(@ad)

    #verifications/fast_verify_info.haml
    = link_to "Verify",
    fast_verify_verification_path(Ad.unverified_ads.last), :method => :put

    #verification_controller.rb
    def verify_info
    @ad = Ad.find(params[:id])
    end

    def fast_verify_info
    @ad = Ad.find(params[:id])
    end

    def fast_verify
    @ad = Ad.find(params[:id])
    @ad.verify!
    if Ad.unverified_ads.size == 0
    redirect_to verifications_path
    else
    redirect_to
    fast_verify_info_verification_path(Ad.unverified_ads.last)
    end
    end

    def verify
    @ad = Ad.find(params[:id])
    @ad.verify!
    if params[:fast] == true
    redirect_to Ad.unverified_ads.last
    else
    redirect_to verifications_path
    end
    end

    --
    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 20, '12 at 1:29p
activeJan 22, '12 at 12:59p
posts4
users3
websiterubyonrails.org
irc#RubyOnRails

People

Translate

site design / logo © 2021 Grokbase