Loading a Partial via Ajax in Rails 3 -
I'm having trouble getting the page to update. I'm completely lost and do not know where from To start, type a travis, I'm not sure which action you actually are here If you are trying to demonstrate, then suppose you want to Suppose that your resource has if you have used the rail to generate your This might look like this: The main part is that you need When you enter a Need to ensure that your end In your controller, make sure that a Secondly, we are going to create a Finally, we believe that our post is partly something like I'm not sure why you are using the JavaScript framework, but here I am using jQuery. I believe if you are using Rail 3.1, then the default framework used by jQuery, otherwise you have to look for it Hope it helps. : Remote => for my form. True Page Initial loads written in partially wrapped in a div tag, which is called a comment, I do not know whether to create a controller or file, or even how to create, partial Submit to the user when clicking on the form. Thanks for any help.
create a new resource.
posted
postcontroller You will have a method
created .
def @ post = post.new (param [: post]) response_to do | Format | If @ post.save format.html {redirect_to (@ post,: notice = & gt; 'Post was created successfully.')} Format.xml {render: xml = & gt; @Post ,: Status = & gt; : Created: Location = & gt; @post} and format.html {renderer: action = & gt; "New"} format.xml {Render: xml = & gt; @ Post. Errors,: Status = & gt; : Unprocessable_entity} End End End
format.js in the
response_to block.
: remote = & gt; True flag on your form or link, you are telling the railroad that you want to request through Ajax, resulting in the
data-remote attribute in your
form Or
a element, and it is used to tell controversial JavaScript to use in exchange for submitting your request. Ajax
format.js response format is
response_to listed in the block (
html < See examples above for / code> and
xml ).
create.js.erb file under your
app / view / post folder. By default, the train is a
action.format.erb file that matches your action and format.
In the app / view / post / create.js.erb file, you can now place your feedback in JavaScript which will update your HTML accordingly. If, for example, you had a list of posts and you wanted to add a new created at the end, then you might have something like this:
App / ideas / something / Show.html ARB / /> code
& lt; H1 & gt; Mail & lt; / H1> & Lt; Div id = "post" & gt; & Lt;% = few posts% & gt; ; & Lt; / Div & gt; & Lt ;! - Here we will join: re-mite = & gt; True choice, which will add data-remote attribute to our form - & gt; & Lt;% = post_for post.new ,: remote = & gt; To be true F | & Gt%; & Lt;% = f.text_area: Text% & gt; & Lt;% = f.submit% & gt; & Lt;% end% & gt;
App / View / Post / Texture JSCB
// Here we are taking our newly created posts and add it to the list shown on $ ('#posts'). Append ("& lt;% = escape_javascript (posted @post)%>);
app / view / post / _post.html.erb
& lt; P class = "post-text" & gt; & Lt;% = @ post.text% & gt; & Lt; / P & gt;
Comments
Post a Comment