views:

25

answers:

2

This seems like a fairly simple problem to me but I have been having some issues.

In one of my views I use something like

<% if current_page?(:controller => "activities", :action => "new") %>
        *Do something here*
<% end %>

and it does something specific on the new page for a form. Easy enough and it works great.

Unfortunately, I've found that when you have a "new activity" form (assume normal scaffolding controller), the url will go from

http://localhost:3000/activities/new

after submitting an error prone form to

http://localhost:3000/activities

but it will still show the new activity form with the respective errors. So basically everything works how it is supposed to EXCEPT that I need the url to be http://localhost:3000/activities/new for the current_page? function to recognize that it is indeed a new form page.

I'm wondering if there is some kind of work around to this issue. Thanks!

OH and here is the controller code, in case anybody needs to see it

Controller Code

      def new
        @activity = Activity.new
      end

      def create
         @activity = Activity.new(params[:activity])
         if @activity.save
            flash[:notice] = "Successfully created activity."
            redirect_to @activity
          else
             render :action => 'new'
          end
       end
+2  A: 

Think you will need to check for create as well as new

<% if current_page?(:controller => "activities", :action => "new") or current_page?(:controller => "activities", :action => "create") %>

not so pretty maybe wrap it up in a helper method?

house9
thanks! that was a "D'oh!" moment for me : )
bob
A: 

You could also check if the created at field is blank. As it won't be set till the activity is created.

PhilCK