gustav
October 8, 2007, 1:56pm
1
Hi! I’m using RJS to process a form in a partial (_newtask.rhtml) and
replace a partial (_tasks.rhtml) in the same view (index.rhtml):
_newtask.rhtml-view *
<%= form_remote_tag :update => “tasks”, :url => { :action => ‘create’ }
%>
task_controller.rb *
def index
@task = Task.new
@projects = Project.find(:all)
@tasks = Task.find(:all)
@timeframes = Timeframe.find(:all)
@tasks_today = Task.find(:all, :conditions => “timeframe_id = 1”)
@tasks_thisweek = Task.find(:all, :conditions => “timeframe_id = 2”)
@tasks_nextweek = Task.find(:all, :conditions => “timeframe_id = 3”)
@tasks_later = Task.find(:all, :conditions => “timeframe_id = 4”)
end
def create
@newtask = Task.new(params[:task])
@newtask.save
@tasks_today = Task.find(:all, :conditions => “timeframe_id = 1”)
@tasks_thisweek = Task.find(:all, :conditions => “timeframe_id = 2”)
@tasks_nextweek = Task.find(:all, :conditions => “timeframe_id = 3”)
@tasks_later = Task.find(:all, :conditions => “timeframe_id = 4”)
end
create.rjs-template *
page[:tasks].replace :partial => “tasks”
When submitting the form and the _tasks-partial updates, the CSS-styling
has disappeared. What have I missed?
Also, is there a way that I can leave out the @task_today etc. from the
create-method. Doesn’t seem very DRY
Thanks!
gustav
October 8, 2007, 2:27pm
2
Why would you need
@tasks_today = Task.find(:all, :conditions => “timeframe_id = 1”)
@tasks_thisweek = Task.find(:all, :conditions => “timeframe_id = 2”)
@tasks_nextweek = Task.find(:all, :conditions => “timeframe_id = 3”)
@tasks_later = Task.find(:all, :conditions => “timeframe_id = 4”)
when creating?
On 10/8/07, Gus Vs [email protected] wrote:
@task = Task.new
@newtask = Task.new(params[:task])
When submitting the form and the _tasks-partial updates, the CSS-styling
has disappeared. What have I missed?
Also, is there a way that I can leave out the @task_today etc. from the
create-method. Doesn’t seem very DRY
Thanks!
–
Ramon T.
gustav
October 8, 2007, 2:37pm
3
Why would you need
@tasks_today = Task.find(:all, :conditions => “timeframe_id = 1”)
@tasks_thisweek = Task.find(:all, :conditions => “timeframe_id = 2”)
@tasks_nextweek = Task.find(:all, :conditions => “timeframe_id = 3”)
@tasks_later = Task.find(:all, :conditions => “timeframe_id = 4”)
when creating?
It doesn’t seem very DRY does it But if I leave them out I get “You
have a nil object when you didn’t expect it!” error in _tasks.rhtml.
This probably relates to why the CSS doesn’t load, but I don’t know
how…
gustav
October 8, 2007, 3:12pm
4
Ah, you might wanna paste your partial too (_tasks).
On 10/8/07, Gustav S. [email protected] wrote:
It doesn’t seem very DRY does it But if I leave them out I get “You
have a nil object when you didn’t expect it!” error in _tasks.rhtml.
This probably relates to why the CSS doesn’t load, but I don’t know
how…
–
Ramon T.
gustav
October 8, 2007, 3:38pm
5
Honestly I can’t explain why your styles are lost… but it might help
if you paste your partial as well, since we know what your rjs does.
On 10/8/07, Gustav S. [email protected] wrote:
I use the RJS to render the partial, is there some reference that I need
to do in the RJS that I’m missing?
–
Ramon T.
gustav
October 8, 2007, 3:29pm
6
Ramon T. wrote:
Ah, you might wanna paste your partial too (_tasks).
I use the RJS to render the partial, is there some reference that I need
to do in the RJS that I’m missing?
gustav
October 8, 2007, 3:44pm
7
Here it goes, many thanks for any input!
index.rhtml
<%= render :partial => "newtask" %>
<%= render :partial => "tasks" %>
_newtask.rhtml
<%= form_remote_tag :update => “tasks”,
:url => { :action => ‘create’ } %>
<%= text_field :task, :description %>
<%= collection_select(:task, :project_id,
@projects , :id, :name) %>
<%= collection_select(:task, :timeframe_id,
@timeframes , :id, :name) %>
<%= submit_tag ‘Create!’, :id => ‘submit’ %>
<%= end_form_tag %>
_tasks.rhtml
Today
<% @tasks_today.each do |task| %>
<%= check_box :task, :completed,
:onchange =>
"$('task_#{task.id}').toggleClassName('completed');" %>
<%= task.description %>
<%= link_to_remote 'Delete', :url => {
:action =>
'destroy', :id => task }, :update => :tasks %>
<%= task.project.name %>
<% end %>
gustav
October 8, 2007, 8:58pm
8
Found it! Some sort of conflict: I needed to remove ":update => “tasks”
from form_remote_tag. Also I moved the div-declaration into the
partials. Thanks!
gustav
October 8, 2007, 4:28pm
9
Gosh, you got me. I don’t know why your CSS wouldn’t work with this.
My only guess is that the CSS doesn’t apply to this because the div
names are different…? :eek:
On 10/8/07, Gustav S. [email protected] wrote:
Here it goes, many thanks for any input!
–
Ramon T.