Created
February 24, 2009 07:38
-
-
Save avk/69465 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Here's a sample from one of my controllers: | |
def create | |
@feed_search = FeedSearch.new(params[:feed_search]) | |
@feed_search.feeds = params[:feeds].delete_if{|url| url==""}.map{|url| Feed.find_or_initialize_by_url(url)} | |
@user = (logged_in?) ? current_user : User.find_by_email_or_register(params[:feed_search][:email]) | |
# search needs activation if user isn't logged in | |
@feed_search.state = (logged_in?) ? 'active' : 'pending' | |
if @feed_search.save | |
@result = logged_in? ? 'created' : @user.active? ? 'login' : 'signup' | |
# associate the user and the search | |
@user.feed_searches << @feed_search | |
else | |
@result = 'error' | |
end | |
end | |
# NOTE: how about a respond_to module inside the controller | |
# whose methods are the names of actions | |
# (e.g. def create in the module v. def respond_to_create in the controller) | |
def respond_to_create | |
respond_to do |format| | |
if @result != 'error' | |
format.html { redirect_to feed_search_path(@feed_search) } | |
format.xml { render :xml => @feed_search, :status => :created, :location => @feed_search } | |
else | |
format.html { render :action => "new" } | |
format.xml { render :xml => @feed_search.errors, :status => :unprocessable_entity } | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment