[Rails] respond to js
Can someone tell me how this works, I just don't understand what's going on here _form.html.erb <%= form_for [post, comment], remote: true, html: { class: "new_blog_comment", id: "new_blog_comment" } do |f| -%> <%=t :leave_a_comment, scope: 'blogit.comments'%> <%= field do %> <%= f.label :body, t(:your_comment, scope: 'blogit.comments') %> <%= f.text_area :body %> <%= errors_on(comment, :body) %> <% end %> <%= actions do %> <%= f.submit t(:add_comment, scope: 'blogit.comments'), :disable_with => t(:adding_comment, scope: 'blogit.comments') %> <% end %> <% end -%> before_action :find_commentable, only: :create def create commentable = commentable_type.constantize.find(commentable_id) @comment = Comment.build_from(commentable, current_user.id, body) user_id = commentable.user_id respond_to do |format| if @comment.save make_child_comment format.html { redirect_to("/page/#{user_id}", :notice => 'Comment was successfully added.') } else format.html { render :action => "new" } end end end def find_commentable @commentable_type = params[:commentable_type].classify @commentable = @commentable_type.constantize.find(params[:commentable_id]) end create.js.erb var $form = $("form#new_blog_comment"); <% if @comment.save %> $("#comments").append("<%= escape_javascript(render(@comment)) %>"); $form.get(0).reset(); <% else %> $form.html("<%= escape_javascript(render('form')) %>"); <% end %> -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscr...@googlegroups.com. To post to this group, send email to rubyonrails-talk@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/fedf8f28-d7ec-4e3f-bf5c-e6be29013781%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [Rails] has_many_through new association for exisitng records
On Thursday, February 8, 2018 at 12:23:43 PM UTC-5, Walter Lee Davis wrote: > > That validation was probably on the person, not the picture, unless you > added validates_associated to the Person class. > > Look at this: > https://github.com/walterdavis/fugee/blob/master/app/controllers/people_controller.rb#L74 > > > and this: > > > https://github.com/walterdavis/fugee/blob/master/app/views/people/_form.html.erb#L25 > > > The rest is scaffolded, there's nothing mysterious here. > > Clone this to your machine, run it in rails server. > > Go to localhost:3000/pictures and add some pictures (just file names). > > Go to localhost:3000/people, and add some people. > > See how you can choose pictures for each person? See how the association > is saved and updated? Watch in the console as the record is saved or > updated from the web. > > Walter > > > On Feb 8, 2018, at 11:36 AM, fugee ohu> wrote: > > > > I created an update action in the persons controller Valitadation was > failing with :name can't be blank so I assumed @person.save was trying to > create a new picture That's why I moved the action from the pictures > controller to the persons controller and changed the action to > @person.update instead of @person.save Did you already understand that? > > Do I have to create routes like "get '/people/:id/addresses' => 'addresses#index', as: 'person_addresses' I was thinking maybe rails already creates those routes from the associations and if I make them explicit maybe I'll mess up the routes -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscr...@googlegroups.com. To post to this group, send email to rubyonrails-talk@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/699cd366-3a04-4a32-b0ce-bdad15f7c16d%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[Rails] local variables in form rendered by partial (rendered by helper) undefined
This goes from controller through some partials to a helper to a form and then rails complains that the local variables in <%= form_for [post, comment], remote: true, ... are undefined https://gist.github.com/mices/bfdf659b74efdb00875ba45bb93f70f7 -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscr...@googlegroups.com. To post to this group, send email to rubyonrails-talk@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/fc190509-3175-44bf-a4aa-87b267168815%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [Rails] Problem With Blacklight Catalog Routes
On 8 February 2018 at 21:25, Dane Terrellwrote: > I've been trying to create it, and nothing seems to work. So my question > is, how do you create it. I've never worked with Ruby On Rails > In that case I suggest you start by working right through a good tutorial such as railstutorial.org, which is free to use online. That will show you the basics of Rails Colin -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscr...@googlegroups.com. To post to this group, send email to rubyonrails-talk@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAL%3D0gLtsQyuqwU5mk8NMk0wB8aU8VDaa7RJVzmx_W%3DS5wz_Ftw%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
Re: [Rails] Problem With Blacklight Catalog Routes
On Thu, Feb 8, 2018 at 1:25 PM, Dane Terrellwrote: > I've been trying to create it, and nothing seems to work. What is "it"? (Top-posting isn't helping here.) > I've never worked with Ruby On Rails You might want to spend a little time learning on a more vanilla Rails app in that case. -- Hassan Schroeder hassan.schroe...@gmail.com twitter: @hassan Consulting Availability : Silicon Valley or remote -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscr...@googlegroups.com. To post to this group, send email to rubyonrails-talk@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CACmC4yDRUgmGuZNFGth3PbbG3xQFvJ059Q5KSGbodxZXV%2Bk3EA%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
Re: [Rails] local variables in _form.html.erb undefined
On Thursday, February 8, 2018 at 7:41:19 PM UTC-5, Walter Lee Davis wrote: > > Show the code where you are trying to render this form. A partial that > renders implicitly (like in a scaffolded CRUD form): > > #/app/views/posts/new.html.erb > <%= render 'form' %> > > ...will get a local variable named `post` in the render context. > > What does your controller look like, and what does the enclosing template > look like that is rendering this partial? > > Walter > > > On Feb 8, 2018, at 6:37 PM, fugee ohu> wrote: > > > > _active_record_post_comments.html.erb > > > > > > <%= render post.comments %> > > > > <% if (user_signed_in? && current_user != User.find(post.blogger_id)) %> > > > > <%= render partial: "blogit/comments/form", locals: { > post: post, comment: comment } %> > > > > <% end %> > > > > _form.html.erb > > > > <%= form_for [post, comment], remote: true, > > html: { > > class: "new_blog_comment", id: "new_blog_comment" } do |f| -%> > > > > error: > > ActionView::Template::Error (undefined local variable or method `post' > for #<#:0x007f607eeeb278> > > Did you mean? @post): > > 1: > > 2: <%= form_for [post, comment], remote: true, > > 3: html: { > > 4: class: "new_blog_comment", id: "new_blog_comment" } do |f| > -%> > > > > > > -- > > You received this message because you are subscribed to the Google > Groups "Ruby on Rails: Talk" group. > > To unsubscribe from this group and stop receiving emails from it, send > an email to rubyonrails-ta...@googlegroups.com . > > To post to this group, send email to rubyonra...@googlegroups.com > . > > To view this discussion on the web visit > https://groups.google.com/d/msgid/rubyonrails-talk/4d482d1f-748e-465a-a541-ca9a069ed6a1%40googlegroups.com. > > > > For more options, visit https://groups.google.com/d/optout. > > class PostsController < ::Blogit::ApplicationController def show @post = Post.find(params[:id]) end show.html.erb <%= render @post %> <%= share_bar_for @post %> <%= render "blogit/posts/post_footer", post: @post %> <%= comments_for @post %> posts_helper.rb def comments_for(post) render(partial: "blogit/posts/#{Blogit.configuration.include_comments}_comments", locals: { post: post, comment: Blogit::Comment.new }) end active_record_comments.html.erb <%= render post.comments %> <% if (user_signed_in? && current_user != User.find(post.blogger_id)) %> <%= render partial: "blogit/comments/form", locals: { post: post, comment: comment } %> <% end %> comments/_form.html.erb <%= form_for [post, comment], remote: true, html: { class: "new_blog_comment", id: "new_blog_comment" } do |f| -%> <%=t :leave_a_comment, scope: 'blogit.comments'%> <%= field do %> <%= f.label :body, t(:your_comment, scope: 'blogit.comments') %> <%= f.text_area :body %> <%= errors_on(comment, :body) %> <% end %> <%= actions do %> <%= f.submit t(:add_comment, scope: 'blogit.comments'), :disable_with => t(:adding_comment, scope: 'blogit.comments') %> <% end %> <% end -%> -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscr...@googlegroups.com. To post to this group, send email to rubyonrails-talk@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/c56a4cea-1cb6-4b9a-9abf-3186ebaacb42%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.