Curtis Edmond
2006-Apr-09 21:32 UTC
[Rails] Best RJS process for what I''m trying to do...
I just wanted to ping this off the list to get some advice since I''m
now pulling my hair out. Thanks in advance for taking any time to look
at this. It''s much appreciated. Now, my problem is my RJS is working
but it''s not inserting how I want it to insert. I have a partial
I''m
rendering in my view that looks like this:
<ul id="meal_names">id="meal_names">
<% @meal_names.each do |item| -%>
<li><b><%= item.name %></b> <font
size="0"><%= link_to "delete", {
:controller => ''meal_names'', :action =>
''destroy'', :id => item.id},
:confirm => "are you sure you want to delete #{ item.name}?"
%></font></li>do |item| -%>
<li><b><%= item.name %></b> <font
size="0"><%= link_to "delete", {
:controller => ''meal_names'', :action =>
''destroy'', :id => item.id},
:confirm => "are you sure you want to delete #{ item.name}?"
%></font></li><li><b><%= item.name %></b>
<font size="0"><%= link_to
"delete", { :controller => ''meal_names'', :action
=> ''destroy'', :id =>
item.id}, :confirm => "are you sure you want to delete #{
item.name}?"
%></font></li>
<% end %>end %>
</ul>
and this does give me a list of names but when i submit a new name, it
gets added to the list as just
<li> #{@name.name} </li>
so it doesn''t have the formatting or the delete button like the other
items. Whenm I refresh the page, then it looks proper. Here''s my
controller add method:
def add
@name = MealName.create( params[:meal_name] )
@meal_names = MealName.find(:all)
@meal_names << @name
render :update do |page|
page.insert_html :bottom, ''meal_names'', "<li>
#{@name.name} </li>"
page.visual_effect :highlight, ''meal_names'', :duration
=> 3
end
end
I thought I could get around this by doing a @meal_names << @name and
that didn''t work. I''m thinking I''m just not doing
this properly. Help!
Kevin Olbrich
2006-Apr-09 22:25 UTC
[Rails] Best RJS process for what I''m trying to do...
Your RJS template is doing exactly what you told it to. If you want all the other link stuff, you have to add it. I suggest creating a partial that does all the formatting you want for each item and then insert that partial to the end of meal_names. On Sunday, April 09, 2006, at 3:32 PM, Curtis Edmond wrote:>I just wanted to ping this off the list to get some advice since I''m >now pulling my hair out. Thanks in advance for taking any time to look >at this. It''s much appreciated. Now, my problem is my RJS is working >but it''s not inserting how I want it to insert. I have a partial I''m >rendering in my view that looks like this: > > ><ul id="meal_names">id="meal_names"> > ><% @meal_names.each do |item| -%> > ><li><b><%= item.name %></b> <font size="0"><%= link_to "delete", { >:controller => ''meal_names'', :action => ''destroy'', :id => item.id}, >:confirm => "are you sure you want to delete #{ item.name}?" >%></font></li>do |item| -%> > ><li><b><%= item.name %></b> <font size="0"><%= link_to "delete", { >:controller => ''meal_names'', :action => ''destroy'', :id => item.id}, >:confirm => "are you sure you want to delete #{ item.name}?" >%></font></li><li><b><%= item.name %></b> <font size="0"><%= link_to >"delete", { :controller => ''meal_names'', :action => ''destroy'', :id => >item.id}, :confirm => "are you sure you want to delete #{ item.name}?" >%></font></li> > ><% end %>end %> > ></ul> > > > >and this does give me a list of names but when i submit a new name, it >gets added to the list as just > ><li> #{@name.name} </li> > >so it doesn''t have the formatting or the delete button like the other >items. Whenm I refresh the page, then it looks proper. Here''s my >controller add method: > > def add > > @name = MealName.create( params[:meal_name] ) > @meal_names = MealName.find(:all) > @meal_names << @name > render :update do |page| > page.insert_html :bottom, ''meal_names'', "<li> #{@name.name} </li>" > page.visual_effect :highlight, ''meal_names'', :duration => 3 > > end > end > > >I thought I could get around this by doing a @meal_names << @name and >that didn''t work. I''m thinking I''m just not doing this properly. Help! >_______________________________________________ >Rails mailing list >Rails@lists.rubyonrails.org >http://lists.rubyonrails.org/mailman/listinfo/rails_Kevin -- Posted with http://DevLists.com. Sign up and save your mailbox.
Curtis Edmond
2006-Apr-10 03:19 UTC
[Rails] Best RJS process for what I''m trying to do...
so I tried that and now I get an RJS error in a popup window it states
[object error]
Here''s what I changed and tried...I created a new partial called
_new_name that is as follows:
<li><b><%= new.name %></b> <font
size="0"><%= link_to "delete", {
:controller => ''meal_names'', :action =>
''destroy'', :id => new.id},
:confirm => "are you sure you want to delete #{new.name}?"
%></font></li>
and I changed my controller code to
page.insert_html :bottom, :partial => ''new_name'', :locals
=> { :new => @name}
what am i missing here?
Kevin Olbrich
2006-Apr-10 03:51 UTC
[Rails] Best RJS process for what I''m trying to do...
Try telling it _where_ to insert the html
page.insert_html :bottom, ''meal_names'', :partial =>
''new_name'', :locals
=> { :new => @name}
Not sure what that error message is all about.
On Sunday, April 09, 2006, at 9:19 PM, Curtis Edmond
wrote:>so I tried that and now I get an RJS error in a popup window it states
>
>[object error]
>
>
>Here''s what I changed and tried...I created a new partial called
>_new_name that is as follows:
>
>
><li><b><%= new.name %></b> <font
size="0"><%= link_to "delete", {
>:controller => ''meal_names'', :action =>
''destroy'', :id => new.id},
>:confirm => "are you sure you want to delete #{new.name}?"
>%></font></li>
>
>
>
>
>and I changed my controller code to
>
>
> page.insert_html :bottom, :partial => ''new_name'',
:locals => { :new
>=> @name}
>
>
>what am i missing here?
>_______________________________________________
>Rails mailing list
>Rails@lists.rubyonrails.org
>http://lists.rubyonrails.org/mailman/listinfo/rails
_Kevin
--
Posted with http://DevLists.com. Sign up and save your mailbox.
That did the trick! I guess that would make sense, telling it where to stick the update and all. Cool beans. Thanks again for taking the time out and setting my head straight, I think i had just been looking at it too long. Kevin Olbrich wrote:> Try telling it _where_ to insert the html > > page.insert_html :bottom, ''meal_names'', :partial => ''new_name'', :locals > => { :new => @name} > > Not sure what that error message is all about. > > On Sunday, April 09, 2006, at 9:19 PM, Curtis Edmond wrote: >>:controller => ''meal_names'', :action => ''destroy'', :id => new.id}, >>=> @name} >> >> >>what am i missing here? >>_______________________________________________ >>Rails mailing list >>Rails@lists.rubyonrails.org >>http://lists.rubyonrails.org/mailman/listinfo/rails > > > _Kevin-- Posted via http://www.ruby-forum.com/.