I’m looking for a tutorial on how to add a comment box to the end of an articles page on one of my sites. Examples of this can be found at the bottom of many web pages on the net, including all the tutorials on the www.asp.net site and www.codeproject.com, I don’t need anything as complex as code project, I just need to be able to put a blog post, a list of comments and a comment box all on the one page in MVC3 or 4.
I have been searching high and low and can’t find a way to do this in MVC3 or 4.
Any help would be greatly appreciated, cheers,
Mike.
Never mind, I worked it out! And now a little extra text so the post is long enough to post!
Cheers,
Mike,
Related
I've been trying to allow for tags to be placed on posts so that I could partition them into different sections of my app. I've looked through various gems and have found that acts_as_taggable_on seems to be the most popular one. After various attempts of implementation from the examples in the github of the gem I have not been able to successfully use it. I've searched extensively for a tutorial on implementation but have found none and was hoping someone would have one for such a thing. I'm sorry for the simple question as I am still relatively new to programming.
Railscasts now has an excellent tutorial on acts_as_taggable.
This is also a nice and simple text intro on how to get it working.
There are a number of tutorials that are just fine. The one mentioned in the previous answer is a good one.
One point that is not obvious to someone new to the RoR world is that there is no actual column in the database for the tags on the target table. I have seen many folks add a "tags" column to their database. No need for that at all and it just confuses things.
When you add the "acts_as_taggable_on :tags" to the model it becomes a virtual column (I know its not a RoR way to express this but if you have a database background its easier to think this way).
If you are going to require that tags have owners follow the example on how to get an objects tags carefully. You can only get that objects tags via "tags_from". You will get a null if you try a simple tags_list.
Hope this helps
So I'm creating a simple application. I have a 'Games' database table and a 'Rules' database table. Each game can have many rules. I want to present a form like this:
Game Title:
Game Description:
Rule #1:
(Click to add another rule)
So the user can click a button to add another text field for additional rules. What is the best way of going about this? Are there form helpers? Any way to return an array of rules? I'm somewhat new to Rails, and my googling didn't provide much help. I may just be being ignorant, but any help would be greatly appreciated!
What you are looking for are called "dynamic forms" and the answer to your question is in the following Railscasts episode.
http://railscasts.com/episodes/403-dynamic-forms
https://github.com/railscasts/403-dynamic-forms
Its kinda late but i hope it helps someone else.
This is old but should be identical to what you are trying to do at the core.
http://railscasts.com/episodes/75-complex-forms-part-3
Just think of Project and Tasks to your Game and Rules.
Use javascript. This would help
http://railscasts.com/episodes/197-nested-model-form-part-2
You'll likely want to use a "game" form with nested "rules" forms. This would be a lengthy answer if I put all the code needed but visiting these should help you right along:
http://railscasts.com/episodes/196-nested-model-form-part-1
http://railscasts.com/episodes/197-nested-model-form-part-2
I'm trying to decide between the two. I don't know ruby or python very well. I found some articles on SO. Are there any recommended sites? Googling only shows one or two. Thank you.
I found a few. Most (if not all) of the articles linked on the first page of the results ought to be enough information to help you make an informed decision.
I asked a question earlier, and got an excellent response, but, being a newbie to Rails and still getting the basics down, I need someone to show me how to set up some scaffolding for the situation that Hates_ was nice enough to outline for me. I've set up my application and whatnot, but I basically want to have, for example purposes:
A "Stories" table, for a list of stories
A "Pages" table, for a list of pages that can be attached to stories
A "LinkedPages" table, to link one page to multiple other pages
The idea is that users can create Stories. Stories have Pages. Pages link to other Pages in a branching sort of way, and Hates_ suggested using a LinkedPages table to assist the process of determining which pages link to which other pages.
If someone could use the example models Hates_ provided on the link above (or give me better ones if needed), and just show me how to get this started, I'd be extremely grateful. Rails has had the highest initial learning curve of any programming or scripting language I've learned in the past, I'm just starting to understand many of the basics.
Thanks in advance!
Here is an updated fast paced video that quickly presents some of the wicked sweet features in Rails via a somewhat contrived Blog tutorial.
http://media.rubyonrails.org/video/rails_blog_2.mov
The presenter crams a lot of information into a very short time frame and does paste in some prepared code from time to time, but over all he hits on many of the key features.
He explains how to set up scaffolding as well in about probably the last 5 mins or so.
I'm just learning Ruby on Rails. I've read a few books, I've watched lots of Railscasts, I've looked at some examples.
However, when working on my first serious project with Rails, I've gotten hung up on how to properly implement some very basic web site features that most tutorials I've seen lack.
For instance: Navigation menus. Lots of tutorials on how to make a static one, but what about dynamic? If I want to make a navigation bar that's different across pages, how would I go about doing that?
I think that the best way to learn things like this is by seeing example code. Are there any good open sourced sites in RoR? Any example code that I can check out?
I guess my question really results to using MVC. The basic idea is really basic, and I understand that. But it seems that most applications have each part completely separate from each other... what if I want to, say, combine data from two models to display on the same page? To take the example I posed, if I have a NavModel and a PageModel, can my PageController access both models? I guess I'd assumed that a PageController can only access a PageModel, and none other. All examples I've seen seem to operate this way...is that a faulty assumption?
Or am I totally missing the point, and is that 'doing it wrong?'
Open Source Rails is a repository of sites implemented in rails.
Which books have you read? I think a better understanding of MVC and Rails would help you more in the long run than sample code, which you may be tempted to copy without understanding.
The problem you're describing isn't really different from finding and displaying any kind of data, which I'm sure you've seen covered in snippets on blogs, etc. (using partials and/or layouts is maybe the only difference).
If you haven't read them already, you should try Agile Web Development with Rails and The Rails Way.
There are also several books that take you through building a sample application that include commentary to make sure you understand what you're doing.
This might help: Dynamic navigation menu using Menuitem model
Your controller can access any of your models, so if PageController needs to access your NavModel that's fine. I think typically the Nav controller or helper would contain the methods necessary to prepare the navigation view, but without knowing the details of your project I can't say for sure - if you think it's part of the Page logic, then put it there.
You may also be interested in this "What goes where" question.
Heres a howto on highlighting the current menu item in the page you are on
http://snippets.dzone.com/posts/show/2016