Static Pages from Railcast

Hi everyone,

I followed the railcast from Ryan at
http://railscasts.com/episodes/117-semi-static-pages and works. But what
I would like to do is on my general layouts have the permalink to be
generated this is where i get confused with the tutorial ruby on rails
http://ruby.railstutorial.org/chapters/

My scaffold is called pages. I though we could fetch the resource by
doing has follow

<%= render @pages %>
But i am getting and error

ArgumentError in Static_pages#home

Showing /home/jean/rail/wyw/app/views/layouts/_footer.html.erb where
line #6 raised:

‘nil’ is not an ActiveModel-compatible object that returns a valid
partial path.
Extracted source (around line #6):

3: Copyright Where you Where 2012
4:
5:
6: <%= render @pages %>
7:
8:


    9:
  • <%= link_to “About”, ‘#’ %>

  • Trace of template inclusion: app/views/layouts/application.html.erb

    Rails.root: /home/jean/rail/wyw

    Application Trace | Framework Trace | Full Trace

    Then the tutorial say i have to add a _page.html.erb which i added into
    the folder of pages, but [email protected] doesnt see it. Not sure what to
    do!!

    Thanks

On 17 July 2012 16:09, Jean-Sbastien D. [email protected] wrote:

Extracted source (around line #6):

3: Copyright Where you Where 2012
4:
5:
6: <%= render @pages %>

Same again, @pages is nil. Try to look at the error and see if you
can understand what it means.

Colin

Colin L. wrote in post #1069081:

On 17 July 2012 16:09, Jean-Sbastien D. [email protected] wrote:

Extracted source (around line #6):

3: Copyright Where you Where 2012
4:
5:
6: <%= render @pages %>

Same again, @pages is nil. Try to look at the error and see if you
can understand what it means.

Colin

Well now what I have done his has follow

<%= render @page.name %>

And get the error has follow:
The partial name (About Us) is not a valid Ruby identifier; make sure
your partial name starts with a letter or underscore, and is followed by
any combinations of letters, numbers, or underscores.

So to me this should be the string About Us and placing has html. Did i
miss something??? I do know that the page.name = “About Us” But why not
just displaying it has a html string. What step did i confused.

On 17 July 2012 17:03, Jean-Sbastien D. [email protected] wrote:

Same again, @pages is nil. Try to look at the error and see if you
your partial name starts with a letter or underscore, and is followed by
any combinations of letters, numbers, or underscores.

So to me this should be the string About Us and placing has html. Did i
miss something??? I do know that the page.name = “About Us” But why not
just displaying it has a html string. What step did i confused.

Have a look at the Rails Guide on Layouts and Rendering. Section 2
describes how to use render, but read and understand the rest of it.

I forget whether you are a beginner. If so then work right through
some tutorials such as railstutorial.org to understand the basics of
Rails, also look at the other Rails Guides.

Colin

On 17 July 2012 17:10, Colin L. [email protected] wrote:

The partial name (About Us) is not a valid Ruby identifier; make sure
I forget whether you are a beginner. If so then work right through
some tutorials such as railstutorial.org to understand the basics of
Rails, also look at the other Rails Guides.

Looking back I see that I have already advised that. How are you
getting on with the tutorials.

Colin

Colin L. wrote in post #1069088:

On 17 July 2012 17:10, Colin L. [email protected] wrote:

Colin

Yes I am new to Ruby on Rails. I have read and try several tutorial in
the last 2 weeks.
But this is what I am trying to do.

I have a create a file Static_Pages/homes which his just a static pages.

It has the following structure

<%= full_title(yield(:title)) %> <%= content_for(full_meta_description(yield(:meta_description))).html_safe %> <%= full_meta_keyword(yield(:meta_keyword)) %> <%= full_meta_author(yield(:meta_author)) %>
<%= stylesheet_link_tag    "application", media: "all" %>
<%= javascript_include_tag "application" %>
<%= render 'layouts/shim' %>
<%= render 'layouts/header' %>
<%= yield %>
<%= render 'layouts/footer' %>

_footer.html would then have page links to my resources pages which
contains static links such About Us, Company News, etc… Based on this
tutorial
http://ruby.railstutorial.org/chapters/user-microposts#sec:manipulating_microposts
section 10.22 you must use render to allow to insert a file which you
then create which can be use if there is an association. However there
is no association, About Us and Company News aren’t related to a user or
somesort.

Any solution that ruby can have if i dont have a model association
between those two field?

Colin L. wrote in post #1069096:

On 17 July 2012 17:50, Jean-Sbastien D. [email protected] wrote:

Reading several tutorials is not sufficient. Work right through
railstutorial.org, entering the code, running it, and doing the
exercises. Make sure you understand absolutely every line of code.

Colin

That my problem, I don’t understand! I have try to make the tutorial but
i don’t get it. Using example 10.22 it says to insert a micropost into a
user field you must do has follow

<%= render @resources %> into the location where you want the micropost
to appear or the content

You then create a file called _micropost.html.erb in the folder
micropost/_micropost.html.erb

And voila, to me this is how i see it, I do see that you might have to
define in the controller users @micropost.user to allow the association
to works. But in my program this particular model doesn’t have an
association. Is there something I miss, does Rails allow a way to go
around this or no. Cause if no, then I must change language

On 17 July 2012 18:04, Jean-Sbastien D. [email protected] wrote:

i don’t get it. Using example 10.22 it says to insert a micropost into a
user field you must do has follow

<%= render @resources %> into the location where you want the micropost
to appear or the content

I can’t find that in the tutorial. Which section and listing number is
it in.

Colin

On 17 July 2012 17:50, Jean-Sbastien D. [email protected] wrote:

Colin L. wrote in post #1069088:

On 17 July 2012 17:10, Colin L. [email protected] wrote:

Colin

Yes I am new to Ruby on Rails. I have read and try several tutorial in
the last 2 weeks.

Reading several tutorials is not sufficient. Work right through
railstutorial.org, entering the code, running it, and doing the
exercises. Make sure you understand absolutely every line of code.

Colin

Colin L. wrote in post #1069113:

On 17 July 2012 18:04, Jean-Sbastien D. [email protected] wrote:

i don’t get it. Using example 10.22 it says to insert a micropost into a
user field you must do has follow

<%= render @resources %> into the location where you want the micropost
to appear or the content

I can’t find that in the tutorial. Which section and listing number is
it in.

Colin

its actually microposts i was refering resources to any resource or
model that exists has broader concept.

But it still his <%= render @microposts %> then you must create a file
with all the information that you want to show in the folder
microposts/_microposts.html.erb

Once this is done then you need to tell in the User controllers

def show
@user = User.find(params[:id])
@microposts = @user.microposts.paginate(page: params[:page])
end

But what if my model doesn’t have a relation between the two! Then i
can’t use it?

On 17 July 2012 20:46, Jean-Sbastien D. [email protected] wrote:

def show
@user = User.find(params[:id])
@microposts = @user.microposts.paginate(page: params[:page])
end

But what if my model doesn’t have a relation between the two! Then i
can’t use it?

Are you just trying to render a static partial?

Colin

Colin L. wrote in post #1069118:

On 17 July 2012 20:46, Jean-Sbastien D. [email protected] wrote:

def show
@user = User.find(params[:id])
@microposts = @user.microposts.paginate(page: params[:page])
end

But what if my model doesn’t have a relation between the two! Then i
can’t use it?

Are you just trying to render a static partial?

Colin

Yes

So my footer can have dynamic link to different page, presented by ryan
in the railcast
http://railscasts.com/episodes/117-semi-static-pages?autoplay=true

On 17 July 2012 20:53, Jean-Sbastien D. [email protected] wrote:

can’t use it?

Are you just trying to render a static partial?

Colin

Yes

How far through the tutorial have you worked?

Colin

Colin L. wrote in post #1069121:

On 17 July 2012 20:53, Jean-Sbastien D. [email protected] wrote:

can’t use it?

Are you just trying to render a static partial?

Colin

Yes

How far through the tutorial have you worked?

Colin

Well the fartest i was was 9, but I retry today, i am going to scratch
it again, I did skip to best fit my program. But it remainds the main
issues is that I can’t simply render a resource into an other page. Is
it at least possible?

On 17 July 2012 21:06, Jean-Sbastien D. [email protected] wrote:

How far through the tutorial have you worked?

Colin

Well the fartest i was was 9, but I retry today, i am going to scratch
it again, I did skip to best fit my program. But it remainds the main
issues is that I can’t simply render a resource into an other page. Is
it at least possible?

The reason I asked was that listing 10.30 shows how to render a fixed
page. Also the other advise I gave to study the rails guide on
rendering would do that. There really is no shortcut, you need to
learn stuff. The best way to start is by carrying on through the
tutorial and studying the rails guides.

Colin

Colin L. wrote in post #1069130:

On 17 July 2012 21:06, Jean-Sbastien D. [email protected] wrote:

How far through the tutorial have you worked?

Colin

Well the fartest i was was 9, but I retry today, i am going to scratch
it again, I did skip to best fit my program. But it remainds the main
issues is that I can’t simply render a resource into an other page. Is
it at least possible?

The reason I asked was that listing 10.30 shows how to render a fixed
page. Also the other advise I gave to study the rails guide on
rendering would do that. There really is no shortcut, you need to
learn stuff. The best way to start is by carrying on through the
tutorial and studying the rails guides.

Colin

I understand well your telling me its possible which his good
I however re did everything from the tutorial and on the test i am
getting error

Here the command
bundle exec rspec spec/requests/static_pages_spec.rb

The result
F

Failures:

  1. Static pages Home page should have the content ‘Sample App’
    Failure/Error: visit ‘/static_pages/home’
    NoMethodError:
    undefined method `visit’ for
    #RSpec::Core::ExampleGroup::Nested_1::Nested_1:0xa1695cc

    ./spec/requests/static_pages_spec.rb:7:in `block (3 levels) in

<top (required)>’

Finished in 0.04033 seconds
1 example, 1 failure

Failed examples:

rspec ./spec/requests/static_pages_spec.rb:6 # Static pages Home page
should have the content ‘Sample App’

Why would visit not be defined? Thanks for your help, not sure why its
gives me this

On 17 July 2012 23:57, Jean-Sbastien D. [email protected] wrote:

getting error
Failure/Error: visit ‘/static_pages/home’

rspec ./spec/requests/static_pages_spec.rb:6 # Static pages Home page
should have the content ‘Sample App’

Why would visit not be defined? Thanks for your help, not sure why its
gives me this

My best guess would be that you have an error in the test code. If
you cannot see it then post static_pages_spec.rb here. Copy/paste it
from your actual code so we can check for typos.

Colin

On 18 July 2012 14:13, Jean-Sbastien D. [email protected] wrote:

gives me this
describe “Static pages” do

describe “Home page” do
it “should have the content ‘Sample App’” do
visit ‘/static_pages/home’
page.should have_content(‘Sample App’)
end
end
end

That is not quite the same as that in Listing 3.9 on
http://ruby.railstutorial.org/chapters/static-pages#top
You seem to have a bit missing at the beginning. Whether that is the
cause of the problem I don’t know.

Colin

Colin L. wrote in post #1069168:

On 17 July 2012 23:57, Jean-Sbastien D. [email protected] wrote:

getting error
Failure/Error: visit ‘/static_pages/home’

rspec ./spec/requests/static_pages_spec.rb:6 # Static pages Home page
should have the content ‘Sample App’

Why would visit not be defined? Thanks for your help, not sure why its
gives me this

My best guess would be that you have an error in the test code. If
you cannot see it then post static_pages_spec.rb here. Copy/paste it
from your actual code so we can check for typos.

Colin

Lol here what I have

spec/requests/static_pages_spec.rb
describe “Static pages” do

describe “Home page” do
it “should have the content ‘Sample App’” do
visit ‘/static_pages/home’
page.should have_content(‘Sample App’)
end
end
end

app/views/layouts/application.html.erb

<%= full_title(yield(:title)) %> < /> < /> < />
<%= stylesheet_link_tag    "application", media: "all" %>
<%= javascript_include_tag "application" %>
<%= csrf_meta_tags %>
<%= render 'layouts/shim' %>
<%= render 'layouts/header' %>
<% flash.each do |key, value| %>
<%= value %>
<% end %> <%= yield %> <%= render 'layouts/footer' %> <%= debug(params) if Rails.env.development? %>

app/views/static_pages/home.html.erb
Sample App

<%= link_to "Sign Up", 'signup_path' %>

And do as follow to run the test
bundle exec rspec spec/requests/static_pages_spec.rb

Jim Oser wrote in post #1069201:

Other people have reported this error:

NoMethodError:
undefined method visit' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_1:0xa1695cc> # ./spec/requests/static_pages_spec.rb:7:inblock (3 levels) in
<top (required)>’

google: rspec visit

In particular see:

https://github.com/rspec/rspec-rails/issues/360

You might want to post your Gemfile.

Hmm i see my issues, i installed the rspec not through my gemfile but
through a command line gem install rspec. Would this be the issue