Redirect_to problem .. caching?

I’m having problems with the code below. The @photo.save seems to work
(an
entry is made in the database), but ‘Success!’ doesn’t appear on the "
tagging.rhtml" page unless I refresh the browser. It looks like some
sort
of caching issue, but, strangely, redirect_to doesn’t work no matter
where I
point it to. I’m not sure what to do…can someone tell me what’s going
on?
(and how to fix it?)

PhotosController

def addtag
@person_id = params[:id].split("_")[1]
@photo_id = params[:where]
@photo = Photo.find(@photo_id)
@photo.people << Person.find(@person_id)
if @photo.save
flash[:notice] = ‘Success!’
# redirect_to :action => ‘list’
# render :action => ‘new’
end
end

For the flash part you’ll need flash.now[:notice] = “Success!” since you
haven’t redirected.

For the redirect_to, I suspect you should be having a double
render/redirect
issue since you’re not telling it to redirect_to :whatevs and return. Am
I
right?

RSL

I should also point out that you’d only use flash.now[:notice] if you’re
not redirecting.

RSL

if @photo.save
  flash[:notice] = 'Success!'
       # redirect_to :action => 'list'
       # render :action => 'new'
end

end

If I just write flash.now[:notice] = “Success!” (no redirection),
nothing happens at all. If I write flash[:notice] (no .now), then
“Success!” will show on another page if refresh my browser or even
click to another page.

Redirecting continues not to work, even written without the render or
flash statements, so it doesn’t seem to be a double render/redirect.

Just to be clear, the three lines after if @photo.save are the three
statements I’ve tried, both together and by themselves - none work!
It’s very strange, because besides being rather elementary, they’re
copied from another def in the same Controller.

Anything else I can try?

I’m pretty much ready to scrap my project. I rewrote everything that
applies to tagging, including the Controller, but no luck. In
‘addtags’, I even placed just flash[:notice] and just redirect_to,
but troubles persisted.

If anyone is interested, before I take down the server, I’d be glad to
show off my application. Just email me and I’ll send you the link.

I’ve had trouble with everything from screen refresh, to documented
bugs/workarounds, to image uploading, to gem installation…it’s too
much. Ruby on Rails doesn’t seem ready for prime time.

Hi Michael,

DON’T GIVE UP!!! I can tell that you are a talented programmer because
you bit off a lot for a first project. Maybe a smaller first project
getting simple to things to work and then adding to it might have saved
a bit of frustration. But I’ve been there as well :slight_smile:

I don’t know if you saw Alan’s response to your “flash” problem on the
other thread. You were missing the “=” in the <%= flash[:notice] %>
statement. Using the equal sign actually inserts the text in the output
html stream. So the way you had it coded it was being executed but
never displayed. Use <% … some code … %> when you simply need to wrap
Ruby code in your rhtml template but not actually output it.

I’m not sure what the redirect problem is but it’s not related to the
flash message. Good luck going forward and don’t quit.

-Paul

Thank you for the encouragement. Last night, I took down the server
and then thought about how else I could create my photo tagging
application. The prospect of SQL statements everywhere terrified me,
so I reinstalled everything (this time not InstantRails) and rewrote
the entire application this afternoon changing the organization a
little. [I’m a graduate student on winter break (not comp sci), so I have the time. :]

However, I STILL have the same redirect_to and flash[:notice] problem!
The commented out statements below all work (when they’re uncommented,
obviously), but neither redirect_to() or flash[:notice] works together
or alone.

def addtag
#person_id = params[:id].split("_")[1]
#photo_id = params[:where]
#photo = Photo.find(@photo_id)
#photo.people << Person.find(@person_id)
#if @photo.save
redirect_to(:controller => ‘taggable’, :action => ‘list’)
flash[:notice] = ‘Great Success!’
#end
end

This is a major problem for this page, because once a tag is dropped on
a photo and the relationship is recorded in the database there needs to
be some sort of feedback (ie. ‘Success!’).

In response to previous suggestions, I have <%= flash[:notice] %> at
the top of my standard layout, so it’s always there in every view.
Just in case, I added another <%= flash[:notice] %> in the tagging
view.

And, just as before, if I drop a tag and then click to another page or
refresh the browser, the flash[:notice] will be displayed! So strange!

Again, any suggestions would be VERY appreciated!

I’m so glad to hear that you got things working. It’d have been a shame
to
have such a bad first experience with Rails taint your view of it or
Ruby.

RSL

I having the same problem.
Did you manage to find the cause or a solution to this issue?

Michael Mandecki wrote:

I’m having problems with the code below. The @photo.save seems to work
(an
entry is made in the database), but ‘Success!’ doesn’t appear on the "
tagging.rhtml" page unless I refresh the browser. It looks like some
sort
of caching issue, but, strangely, redirect_to doesn’t work no matter
where I
point it to. I’m not sure what to do…can someone tell me what’s going
on?
(and how to fix it?)

PhotosController

def addtag
@person_id = params[:id].split("_")[1]
@photo_id = params[:where]
@photo = Photo.find(@photo_id)
@photo.people << Person.find(@person_id)
if @photo.save
flash[:notice] = ‘Success!’
# redirect_to :action => ‘list’
# render :action => ‘new’
end
end

Hi gang,

I had the same problem. I’ve just figured out the fix. Use:

redirect_to :action => :symbol

instead of

redirect_to :action => ‘string’

Then the flash message is shown.

Too bad you have to remember that distinction, though. That shouldn’t
be necessary.