1

I'm very new to Rails and am trying to get started but have run into a problem, I've searched around and it seems like a lot of people have had the same problem but I either don't understand their solutions or don't seem to have the files that they changed to fix it,

I'm currently using Windows and running all commands through Git Bash, I have Ruby v2.2.4p230, and Rails v4.2.5.1, through Git Bash, I have just run these commands

cd ~/Desktop
rails new pinteresting
cd pinteresting
rails generate controller pages home
rails server

So now if I go to the localhost3000, it gives me the basic sample layout of the app which is fine, but then I try to visit the pages/home and I get one of three errors,

Missing helper file helpers/c:/users/acer_pc/desktop/pinteresting/app/helpers/application_helper.rb_helper.rb

Missing helper file helpers/c:/users/acer_pc/desktop/pinteresting/app/helpers/pages_helper.rb_helper.rb

Missing template pages/home, application/home with {:locale=>[:en], :formats=>[:html], :variants=>[], :handlers=>[:erb, :builder, :raw, :ruby, :coffee, :jbuilder]}. Searched in: * "c:/Users/Acer-PC/desktop/pinteresting/app/views"

If it helps, this is the folder https://github.com/Fuledbyramen/pinteresting

rohin-arka
  • 779
  • 4
  • 10
Fuledbyramen
  • 185
  • 1
  • 3
  • 16
  • Works fine, might be an issue with Windows. – danielrsmith May 04 '16 at 17:45
  • Check out: http://stackoverflow.com/questions/27871726/strange-error-in-rails-missing-helper/27909917#27909917 – danielrsmith May 04 '16 at 17:49
  • What is the value of $HOME in your Git Bash shell? [Here](http://markb.co.uk/portable-git-windows-setting-home-environment-variable.html) is a guide to setting $HOME properly so that it doesn't have Windows pathnames mixed in with the *nix pathnames that Rails is generating. – Michael Gaskill May 04 '16 at 20:02
  • If you want to learn about creating static pages refer this https://www.railstutorial.org/book/static_pages – Nirupa May 04 '16 at 22:56

3 Answers3

1

I set up your project on my localhost and I am able to visit http://localhost:3000/pages/home without any issues.

You have set get 'pages/home' three times in routes.rb, one is enough.

dodo121
  • 114
  • 1
  • 5
  • Yeah looks like wasn't a file issue, just something to do with Rails or Ruby not working on my computer and its files – Fuledbyramen May 06 '16 at 05:31
1

Thank you guys for all the replies, finally figured it out, like all the other SO answers, its something to do with the capitalization of file names which I just couldn't figure out, so I just wrote it directly to /c instead of ~/desktop, then in application.html.erb just changed application in lines 5 and 6 to default and it works... Wasn't missing any files or needed to do any commands or anything

Fuledbyramen
  • 185
  • 1
  • 3
  • 16
0

You've only generated the controller for pages and created an action called home for it. You have some additional steps needed, as well, to fill out all of the functionality.

There's a "fast" way to create the whole lot: scaffold. Try using this command:

rails generate scaffold pages

Since you've already created your controller, when it asks if you want to overwrite your controller, you can answer 'N' to the question. You can answer 'N' to any other questions that it asks, as well, especially if you've already made changes to any of the files, so that you don't lose those changes.

If you want to go the long way around, you'll also need to create at least some of these:

  • Model
  • Migration
  • Views

To create the Model, you can use another similar command:

rails generate model pages

This will create a page.rb file in your app/models directory. This maps to your database table that stores the details for each page.

You can also generate the Migration to create the pages database table, like so:

rails generate migration CreatePages

You'll need to provide the basic details of the pages table structure, following the Rails migration guidelines, which you can find here.

Finally, you'll need to create the Views for each action. This is primarily what's missing from your current implementation, because generating the controller doesn't generate the corresponding view files.

To do this, you'll want to create a new file called home.html.erb (if it doesn't already exist) in the app/views/pages directory. Simply having this file will be enough to make it past the point that you need, but you'll probably want to put something in it. Let's display the time:

<p>At the tone, it will be: <%= DateTime.now.strftime("%Y-%m-%d %H:%M:%S") %></p>

This should give you a decent starting point to build out the rest of what you need.

When you're starting out, however, try to use the scaffold generator until you're comfortable with where the pieces are all located and how to create them individually. And enjoy!

Michael Gaskill
  • 7,913
  • 10
  • 38
  • 43
  • I changed some of the files around in my computer but not the application and it worked, looks like i didnt need to do any of these commands, thank you very much though – Fuledbyramen May 06 '16 at 05:32