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: </small> 5: 6: <%= render @pages %> 7: <nav> 8: <ul> 9: <li><%= link_to "About", '#' %></li> 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 render@pages doesnt see it. Not sure what to do!! Thanks
on 2012-07-17 17:09
on 2012-07-17 17:50
On 17 July 2012 16:09, Jean-Sbastien D. <lists@ruby-forum.com> wrote: > > Extracted source (around line #6): > > 3: Copyright Where you Where 2012 > 4: </small> > 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
on 2012-07-17 18:03
Colin Law wrote in post #1069081: > On 17 July 2012 16:09, Jean-Sbastien D. <lists@ruby-forum.com> wrote: >> >> Extracted source (around line #6): >> >> 3: Copyright Where you Where 2012 >> 4: </small> >> 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 2012-07-17 18:12
On 17 July 2012 17:03, Jean-Sbastien D. <lists@ruby-forum.com> 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 2012-07-17 18:13
On 17 July 2012 17:10, Colin Law <clanlaw@googlemail.com> 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
on 2012-07-17 18:50
Colin Law wrote in post #1069088: > On 17 July 2012 17:10, Colin Law <clanlaw@googlemail.com> 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 <!DOCTYPE html> <html> <head> <title><%= full_title(yield(:title)) %></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' %> </head> <body> <%= render 'layouts/header' %> <div class="container"> <%= yield %> </div> <%= render 'layouts/footer' %> </body> </html> _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-microp... 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?
on 2012-07-17 18:55
On 17 July 2012 17:50, Jean-Sbastien D. <lists@ruby-forum.com> wrote: > Colin Law wrote in post #1069088: >> On 17 July 2012 17:10, Colin Law <clanlaw@googlemail.com> 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
on 2012-07-17 19:04
Colin Law wrote in post #1069096: > On 17 July 2012 17:50, Jean-Sbastien D. <lists@ruby-forum.com> 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 2012-07-17 21:40
On 17 July 2012 18:04, Jean-Sbastien D. <lists@ruby-forum.com> 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 2012-07-17 21:46
Colin Law wrote in post #1069113: > On 17 July 2012 18:04, Jean-Sbastien D. <lists@ruby-forum.com> 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 2012-07-17 21:51
On 17 July 2012 20:46, Jean-Sbastien D. <lists@ruby-forum.com> 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
on 2012-07-17 21:53
Colin Law wrote in post #1069118: > On 17 July 2012 20:46, Jean-Sbastien D. <lists@ruby-forum.com> 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-pag...
on 2012-07-17 21:59
On 17 July 2012 20:53, Jean-Sbastien D. <lists@ruby-forum.com> 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
on 2012-07-17 22:06
Colin Law wrote in post #1069121: > On 17 July 2012 20:53, Jean-Sbastien D. <lists@ruby-forum.com> 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 2012-07-17 22:28
On 17 July 2012 21:06, Jean-Sbastien D. <lists@ruby-forum.com> 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
on 2012-07-18 00:57
Colin Law wrote in post #1069130: > On 17 July 2012 21:06, Jean-Sbastien D. <lists@ruby-forum.com> 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 2012-07-18 08:34
On 17 July 2012 23:57, Jean-Sbastien D. <lists@ruby-forum.com> 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 2012-07-18 15:13
Colin Law wrote in post #1069168: > On 17 July 2012 23:57, Jean-Sbastien D. <lists@ruby-forum.com> 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 <!DOCTYPE html> <html> <head> <title><%= full_title(yield(:title)) %></title> <<%= full_meta_description(yield(:meta_description)) %> /> <<%= full_meta_keyword(yield(:meta_keyword)) %> /> <<%= full_meta_author(yield(:meta_author)) %> /> <%= stylesheet_link_tag "application", media: "all" %> <%= javascript_include_tag "application" %> <%= csrf_meta_tags %> <%= render 'layouts/shim' %> </head> <body> <%= render 'layouts/header' %> <div class="container"> <% flash.each do |key, value| %> <div class="alert alert-<%= key %>"><%= value %></div> <% end %> <%= yield %> <%= render 'layouts/footer' %> <%= debug(params) if Rails.env.development? %> </div> </body> </html> app/views/static_pages/home.html.erb Sample App <div class="left_column"> </div> <div class="right_column"> <%= link_to "Sign Up", 'signup_path' %> </div> And do as follow to run the test bundle exec rspec spec/requests/static_pages_spec.rb
on 2012-07-18 15:59
On 18 July 2012 14:13, Jean-Sbastien D. <lists@ruby-forum.com> 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
on 2012-07-18 16:08
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:in `block (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.
on 2012-07-18 16:13
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:in `block (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
on 2012-07-18 17:20
What i am doing wrong??
So I am at chapter 8, and everything seem to be working except that once
loggin I am apparently not login but do see some of the information such
as show correct user.
Here what I have
app/controllers/customers.rb
class CustomersController < ApplicationController
def show
@customer = Customer.find(params[:id])
end
def create
@customer = Customer.new(params[:customer])
if @customer.save
sign_in @customer
flash[:success] = "Welcome to Where you Where"
redirect_to @customer
# Handle a successful save.
else
render 'new'
end
end
def new
@customer = Customer.new
end
def edit
@customer = Customer.find(params[:id])
end
def update
if @customer.update_attributes(params[:customer])
flash[:success] = "Profile updated"
sign_in @customer
redirect_to @customer
else
render 'edit'
end
end
private
def signed_in_customer
redirect_to signin_path, notice: "Please sign in." unless
signed_in?
end
def correct_customer
@customer = Customer.find(params[:id])
redirect_to(root_path) unless current_customer?(@customer)
end
end
I have change the name of the resource from user to customer for trying
different then the person
this is my session help found in the folder
app/helpers/session.rb
module SessionsHelper
def sign_in(customer)
cookies.permanent[:remember_token] = customer.remember_token
self.current_customer= customer
end
def current_customer=(customer)
@current_customer = customer
end
def current_customer?(customer)
customer == current_customer
end
def current_customer
@current_customer ||=
Customer.find_by_remember_token(cookies[:remember_token])
end
def sign_in(customer)
cookies.permanent[:remember_token] = customer.remember_token
self.current_customer = customer
end
def signed_in?
!current_customer.nil?
end
def sign_out
cookies.delete(:remember_token)
self.current_customer = nil
end
end
Here his my header just in case i made a small mistake
<header class="navbar navbar-fixed-top">
<div class="navbar-inner">
<div class="container">
<nav>
<ul class="nav pull-right">
<li><%= link_to "Home", root_path %></li>
<% if signed_in? %>
<li><%= link_to "Customers", '#' %></li>
<li id="fat-menu" class="dropdown">
<a href="#" class="dropdown-toggle"
data-toggle="dropdown">
Account <b class="caret"></b>
</a>
<ul class="dropdown-menu">
<li><%= link_to "Profile", current_customer %></li>
<li><%= link_to "Settings", '#' %></li>
<li class="divider"></li>
<li>
<%= link_to "Sign out", signout_path, method: "delete"
%>
</li>
</ul>
</li>
<% else %>
<li><%= link_to "Sign in", signin_path %></li>
<% end %>
</ul>
</nav>
</div>
</div>
</header>
Again i only see sign and home as link has i am assuming something his
wrong with my sign process
on 2012-07-18 19:34
Jean-Sébastien D. wrote in post #1069202: > Jim Oser wrote in post #1069201: >> Other people have reported this error: Thanks. I am wondering if its actually possible to see into the application controller other resources Example class ApplicationController < ActionController::Base protect_from_forgery include SessionsHelper @pages = Page.all end app/layout/_footer.html.erb <% @pages.each do |page| %> <li> <%= @page.name %> </li> <% end %> Thanks in advance
Please log in before posting. Registration is free and takes only a minute.
Existing account
(Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
Log in with Google account | Log in with Yahoo account
No account? Register here.