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!
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Ramon Miguel M. Tayag
2007-Oct-08 12:27 UTC
Re: CSS style disappear when using RJS and page.replace
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 <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > 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!-- Ramon Tayag --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Gustav Stockholm
2007-Oct-08 12:37 UTC
Re: CSS style disappear when using RJS and page.replace
> 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... -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Ramon Miguel M. Tayag
2007-Oct-08 13:12 UTC
Re: CSS style disappear when using RJS and page.replace
Ah, you might wanna paste your partial too (_tasks). :) On 10/8/07, Gustav Stockholm <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> 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 Tayag --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Gustav Stockholm
2007-Oct-08 13:29 UTC
Re: CSS style disappear when using RJS and page.replace
Ramon Tayag 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? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Ramon Miguel M. Tayag
2007-Oct-08 13:37 UTC
Re: CSS style disappear when using RJS and page.replace
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 Stockholm <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> 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 Tayag --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Gustav Stockholm
2007-Oct-08 13:44 UTC
Re: CSS style disappear when using RJS and page.replace
Here it goes, many thanks for any input!
index.rhtml
<div id="screen">
<div id="new_task">
<%= render :partial => "newtask" %>
</div>
<div id="tasks">
<%= render :partial => "tasks" %>
</div>
</div>
_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
<div id="today">
<h2>Today</h2>
<ul>
<% @tasks_today.each do |task| %>
<li id="task_<%= task.id %>" class="<%=
''completed'' if
task.completed == 1 %>">
<div class="checkbox"><%= check_box :task, :completed,
:onchange =>
"$(''task_#{task.id}'').toggleClassName(''completed'');"
%></div>
<div class="description"><%= task.description
%></div>
<div class="actions"><%= link_to_remote
''Delete'', :url => {
:action =>
''destroy'', :id => task }, :update => :tasks
%></div>
<div class="project"><%= task.project.name
%></div>
</li>
<% end %>
</ul>
</div>
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Ramon Miguel M. Tayag
2007-Oct-08 14:27 UTC
Re: CSS style disappear when using RJS and page.replace
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 Stockholm <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Here it goes, many thanks for any input!-- Ramon Tayag --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Gustav Stockholm
2007-Oct-08 18:58 UTC
Re: CSS style disappear when using RJS and page.replace
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! -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---