I really love this ajax scaffold plugin! It works great with some of
my simpler examples.
But now I want to do something bejond those simple examples and stuck
with some problems.
1. Implement a toggle link (e.g Select/Unselect) on each row in a list
- I have overriden _row.rhtml to add a new action "Select" in the
actions area of the list. Works!
<td>
<% select_label = (is_row_selected(row.id) ?
"Unselect":"Select") %>
<% select_options = @options.merge(:action =>
'select_row'+@suffix) %>
<%= link_to_remote select_label,
{ :url => select_options },
{ :href => url_for( select_options ) } %>
</td>
- I have added a new action in my controller that gets triggered by
the select action. Works!
def select_row
row_id = params['id'].to_i
if session[:selected_row]
if session[:selected_row].to_i == row_id.to_i
session[:selected_row] = nil
else
session[:selected_row] = row_id
end
else
session[:selected_row] = row_id
end
redirect_to :action => "list"
end
The basic function should be like this now:
Hit "Select" on a certain row => Store row_id to session, change
action label to "Unselect"
Hit "Select" on another row =>
Store new row_id to session, change action label to "Unselect".
Change old to "Select"
Hit "Unselect" on selected row => remove row_id from session. Change
label to "Select"
When I hit the "Select" action on a certain row I can see from my
debugging, that the action "select_row" gets called. So the basic
functionality is working.
My Problem: The label only toggles when I manually hit "Reload". The
redirect_to does not seem to work. So what´s wrong?
2. Redirect to another conroller/action from a custom action
What I want to do next is to provide a certain action on the selected
row (e.g. analyse). This should take the data from the selected row
and compute some new data in another table with it.
So when I hit the analyse action in my view the processing should
start and after that I want the user to get redirected to the new page
with the results of the different table.
I have this in my controller:
def analyse
row_id = session[:selected_row]
print "Going to analyse row #{row_id}...\n"
# Do the analyse and store results elsewhere ...
print "...done!\n"
redirect_to :controller => "result", :action => "list")
end
And again: The action gets called perfectly but the redirect_to is not
taking me to the results page. What´s wrong here?
I have the feeling that I have general misunderstanding on this
redirecting thing in combination with ajax scaffold. I tried it the
same way I would have used with plain rails (which worked perfectly in
different examples). Maybe there is another approach on how this
should be done.
Hmmpf, it´s quite dark in here, could somebody please bring in some
light for me? :-)
Thanks & Regards,
Christian
Hi Folks,
I really love this ajax scaffold plugin! It works great with some of
my simpler examples.
But now I want to do something bejond those simple examples and stuck
with some problems.
1. Implement a toggle link ( e.g Select/Unselect) on each row in a list
- I have overriden _row.rhtml to add a new action "Select" in the
actions area of the list. Works!
<td>
<% select_label = (is_row_selected( row.id) ?