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?
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.
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 :)
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
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!
-- Long
http://MeandmyCity.com/ - Free, searchable business directory for local communities
http://edgesoft.ca/blog/read/2 - No-Cookie Session Support plugin for Rails
Yes, I wanted to show the various statements I've tried (in combination
together and alone). The reality is even these most basic def's won't
work:
def addtag
redirect_to(:controller => 'photos', :action => 'list')
end
-- or --
def addtag
flash[:notice] = 'Great Success!'
end
Yet 'addtag' will execute other statements, such as those required to
make a database entry.
I don't really understand how to write breakpoints and test on Rails,
but maybe someone can help me there? [Very explicitly though, because
it's new to me.]
The problem is that the drag/drop support is provided via the prototype
and scriptaculous libraries. Therefore, the Ajax callback into your
photo/addtag method is expecting Javascript back. Your current
redirect, while it will work, is sending html back to the browser which
it is not expecting. That is why the flash message appears not to work
and also why the next page picks it up. Try the following:
render :update do |page|
page.redirect_to :action => 'tagging'
end
-Paul
>From here, I'm going to have the function add the name of the dropped
person/tag to a list under each picture.
Thank you Paul - and everyone - for your help!
# The working code!
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] = "Great success!"
render :update do |page|
page.redirect_to :action => 'list'
end
end
end
--
Posted via http://www.ruby-forum.com/.
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.