Hi guys,
can anyone explain how to show error_messages_on (like back in Rails
2 , without Ajax) fields that didnt'' pass the validation the jquery
way.
I googled for about 2 hours now and found nothing. Jquery works fine
and adds the content to my table, but im totally stuck with the whole
error/validation thing.
My form looks like this:
<%= form_for Translation.new , :remote => true do |f| %>
<table>
<tr>
<td>
<%= f.label :locale %><br />
<%= f.text_field :locale %>
</td>
<td>
<%= f.label :key %><br />
<%= f.text_field :key %>
</td>
</tr>
<tr>
<td>
<%= f.label :value %><br />
<%= f.text_area :value , :rows => 3%>
</td>
<td>
<%= f.label :interpolations %><br />
<%= f.text_area :interpolations, :rows => 3 %>
</td>
</tr>
<tr>
<td>
<%= f.label :is_proc %><br />
<%= f.check_box :is_proc %>
</td>
<td></td>
</tr>
</table>
<p><%= f.submit t(''translation.create'')
%></p>
<% end %>
Create action like this:
def create
if @translation.save
flash[:notice] = "Successfully created translation."
respond_to do |format|
format.html { redirect_to @translation }
format.js
end
else
respond_to do |format|
format.html { render :action => ''new''}
# show what went wrong with jquery
end
end
end
and create.js.erb
/* Insert a notice between the last comment and the comment form */
$("#translation-notice").html(''<div class="flash
notice"><%escape_javascript(flash.delete(:notice))
%></div>'');
/* Add the new comment to the bottom of the comments list */
$("#translations").prepend("<%escape_javascript(render(@translation))
%>");
/* Highlight the new comment */
$("#translation-<%= @translation.id
%>").effect("highlight", {},
3000);
/* Reset the comment form */
$("#new_translation")[0].reset();
Adding validated data works but please give me hint with error
validation thing.
thanks
--
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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
the problem is
def create
if @translation.save
flash[:notice] = "Successfully created translation."
respond_to do |format|
format.html { redirect_to @translation }
format.js
end
else
respond_to do |format|
format.html { render :action => ''new''}
# show what went wrong with jquery
end
end
you can pass an action to format.js, apparently since most examples dont
pass anything you didnt notice that format,js is doing this
format.js { render :action => "create"} and calls a create.js.erb
it does this if you only put format.js but you can render other actions like
this
def create
if @translation.save
flash[:notice] = "Successfully created translation."
respond_to do |format|
format.html { redirect_to @translation }
format.js { render :action => "success"}
end
else
respond_to do |format|
format.html { render :action => ''new''}
format.js { render :action => "failure"}
end
end
and have an success.js.erb with code for displaying the "everything went
cool" updates and a failure.js.erb to display the "epic fail"
updates.
--
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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
there is no need to add a success or failure actions to the controller, when rails does not find and action in a controller it tries to display a template with the corresponding name anyway. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Thanks mate. 2010/9/27 radhames brito <rbritom-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>> > the problem is > > def create > if @translation.save > flash[:notice] = "Successfully created translation." > respond_to do |format| > format.html { redirect_to @translation } > format.js > end > else > respond_to do |format| > format.html { render :action => ''new''} > # show what went wrong with jquery > end > end > > you can pass an action to format.js, apparently since most examples dont > pass anything you didnt notice that format,js is doing this > > format.js { render :action => "create"} and calls a create.js.erb > > it does this if you only put format.js but you can render other actions > like this > > > > def create > if @translation.save > flash[:notice] = "Successfully created translation." > respond_to do |format| > format.html { redirect_to @translation } > format.js { render :action => "success"} > > end > else > respond_to do |format| > format.html { render :action => ''new''} > format.js { render :action => "failure"} > end > end > > and have an success.js.erb with code for displaying the "everything went > cool" updates and a failure.js.erb to display the "epic fail" updates. > > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. >-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
so, rename create.js.erb to success.js.erb and create a failure.js.erb and refer to format.js in the controller? 2010/9/27 radhames brito <rbritom-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>> there is no need to add a success or failure actions to the controller, > when rails does not find and action in a controller it tries to display a > template with the corresponding name anyway. > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. >-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
sure , add the corresponding logic to the failure.js.erb -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
refer to them in the create action like i showed , no need to create action in the controller just the template in the views folder -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Apparently Analagous Threads
- Rails 3 - Creating a comment and then returning the Partial with JUST the new comment
- Finding HTML attributes with jQuery in Rails 3.1
- Appending a Rails Partial with jQuery
- Ajax and rails 3 UJS (jquery)
- HowTo; Rails 3, having Tabs that load content via jQuery ... No Page Refesh