Hi everybody, and first please forgive me for my bad english.
I’m working for few weeks on a RoR project for my professional training,
I have to develop a new app, I have use scaffold to create all the
models, controller and view for each table of my database but now I want
to create a new view which doesn’t correspond to any model in my
database because I must be able to write some informations and then fill
my tables.
I try to use rails g controller and then to create manually a view but
after this if i use resources:currentoperations in routes.rb that will
create the routes for new, index _form views but i don’t want them.
I also try to use pages.controller where i define for exemple currentop
which is a views in the repertory view/pages/currentop but it seems to
be difficult to define methodes for this view because in routes.rb it’s
not define as a resources but like this get “pages/operation_en_cours”
get “concerns/operation_en_cours”
after this if i use resources:currentoperations in routes.rb that will
create the routes for new, index _form views but i don’t want them.
Have a look at the Rails Guide on Routing, that will show you how to
create just the routes you want. Also have a look at all the other
guides as well. In addition it would be a good idea to work right
through a good tutorial such as railstutorial.org, which is free to
use online. That will show you the basics of Rails. Do that first
and you will know the answers to your questions.
after this if i use resources:currentoperations in routes.rb that will
create the routes for new, index _form views but i don’t want them.
Have a look at the Rails Guide on Routing, that will show you how to
create just the routes you want. Also have a look at all the other
guides as well. In addition it would be a good idea to work right
through a good tutorial such as railstutorial.org, which is free to
use online. That will show you the basics of Rails. Do that first
and you will know the answers to your questions.
Colin
Thanks for your answer Colin but I have already watched most of rails’
guide and tutorials but I don’t find what I want to do. I haven’t find
an exemple of a view without model because the major part of exemples
are made with scaffolds.
My app is for an internal production of an industry and I need a view
for the operatives where they can fill fields from different tables!!
I’m looking for a scpecific method to do this correctly.
Thanks for your answer Colin but I have already watched most of rails’
guide and tutorials but I don’t find what I want to do. I haven’t find
an exemple of a view without model because the major part of exemples
are made with scaffolds.
If you worked through railstutorial then you cannot have been paying
much attention, as the demo app starts with exactly what you are
asking for [1]. As I said, I suggest you work right through that
tutorial (not just skim through it) that will help you to understand
the basics of rails.
My app is for an internal production of an industry and I need a view
for the operatives where they can fill fields from different tables!!
Once you have it working with static pages then you just need to fetch
the data from the database to put on the pages.
I have already my static pages just like he did but he didn’t show how
to fetch the data from my database or to fill my tables.
I can assure you that railstutorial.org most certainly shows you how
to fetch data from the database. I have also pointed you at the Rails
Guides and you said you had looked at them. Have another look at the
one on ActiveRecord Query Interface for different ways to fetch data.
I don’t understand what you mean by ‘fill my tables’, but once again,
I am sure you would be able to answer the questions yourself if you
worked right through the tutorial.
If you worked through railstutorial then you cannot have been paying
much attention, as the demo app starts with exactly what you are
asking for [1]. As I said, I suggest you work right through that
tutorial (not just skim through it) that will help you to understand
the basics of rails.
That’s right that i didn’t do all thinks that he did like tests but the
reason why is because I’m not sure that with static_page I can do what I
want and I’m looking for the best method.
Indeed at the begining it seems to be good but if you pay attention he
didn’t declare new methodes in pages_static.controller because in these
pages he just put some links with other web sites or just give some
informations
Once you have it working with static pages then you just need to fetch
the data from the database to put on the pages.
Colin
I have already my static pages just like he did but he didn’t show how
to fetch the data from my database or to fill my tables.
Hint: you don’t. ActiveRecord is completely orthogonal to views.
You’re right because I don’t refer to the ActiveRecord link but to railstutorial.org!!
I haven’t manage to do what I want to do but may be the login/logout
chapter of railstutorial.org will help me because I realize that he
creates controller and view for Session and session doesn’t refer to any
special class.
I can assure you that railstutorial.org most certainly shows you how
to fetch data from the database. I have also pointed you at the Rails
Guides and you said you had looked at them. Have another look at the
one on ActiveRecord Query Interface for different ways to fetch data.
Indeed they show how to fetch data from the database but I have only
seen exemples with “scaffold’s views”, I mean _form, new, index…but I
haven’t find exemples using other views like in my case. But I will
search again in the tutorial following your advise.
I don’t understand what you mean by ‘fill my tables’, but once again,
I am sure you would be able to answer the questions yourself if you
worked right through the tutorial.
Colin
Once again I’am sorry for my bad english, by ‘fill my tables’ I wanted
to say
‘populate the database’
I have looked more preciselly what does he do in railstutorial.org but
even login/logout chapter doesn’t help me. Indeed he use resources in
he’s routes. Then he rename new, destroy… path’s in ‘/login’ ‘/logout’
but in my case I can’t do the same thing…
I have no more ideas, and I have read all the tutorial is someone can
help me?
I don’t think anyone knows what it is that you do not know how to do.
I think it is something to do with routing but am not sure. Please
describe just the bit you have a problem with, not the whole
requirement.
Colin
I will have difficults to discribe a problem, because it’s not something
in my code that doesn’t work but just that I can’t find a process
(tutorial) for rails4 explaining how to create view without model.
in my code that doesn’t work but just that I can’t find a process
(tutorial) for rails4 explaining how to create view without model.
But as you said yourself the tutorial does “create a view without a
model”. It is easy. All you have to do is make a controller file
controllers/somename_controller.rb, put the desired actions in it,
create view files such as views/somename/theaction.html.erb and put
the routes in routes.rb. I don’t know which bit you are having a
problem with.
But as you said yourself the tutorial does “create a view without a
model”. It is easy. All you have to do is make a controller file
controllers/somename_controller.rb, put the desired actions in it,
create view files such as views/somename/theaction.html.erb and put
the routes in routes.rb. I don’t know which bit you are having a
problem with.
That is what I did, I have create new controller named saisie, and in
views I have /saisie/index then I wrote in the controller:
@test=“failed”
def index
def change
@test=“succed”
end
end
But I can’t call my methode ‘change’ with a button like I did in other
view like this:
<%= link_to t(’.change’, :default => t(“helpers.links.change”)),
change_saisie_path(task),
:method => :put,
:class => ‘btn btn-mini’%>
I think it’s because I used this when I have a model that is not the
case here. Do you know other way to call my methode?
I believe railstutorial uses rails 4.
In the gemfile of his project on gitHub -> gem ‘rails’, ‘3.0.12’
That’s why I said he used rails 3.
views I have /saisie/index then I wrote in the controller:
<%= link_to t(‘.change’, :default => t(“helpers.links.change”)),
change_saisie_path(task),
:method => :put,
:class => ‘btn btn-mini’%>
I think it’s because I used this when I have a model that is not the
case here. Do you know other way to call my methode?
So your problem is not creating a view without a model, it is invoking
an action from a view. It is no good just saying that you can’t call
the action, what error are you getting? It does not look to me as if
that line is valid, look at the parentheses. Also the second
parameter should be the url. Check the docs for link_to.
I believe railstutorial uses rails 4.
In the gemfile of his project on gitHub → gem ‘rails’, ‘3.0.12’
That’s why I said he used rails 3.
I have looked more preciselly what does he do in railstutorial.org but
even login/logout chapter doesn’t help me. Indeed he use resources in
he’s routes. Then he rename new, destroy… path’s in ‘/login’ ‘/logout’
but in my case I can’t do the same thing…
I have no more ideas, and I have read all the tutorial is someone can
help me?
I don’t think anyone knows what it is that you do not know how to do.
I think it is something to do with routing but am not sure. Please
describe just the bit you have a problem with, not the whole
requirement.
So your problem is not creating a view without a model, it is invoking
an action from a view. It is no good just saying that you can’t call
the action, what error are you getting? It does not look to me as if
that line is valid, look at the parentheses. Also the second
parameter should be the url. Check the docs for link_to.
You were right the issue came from the link_to structure. What is
working for is
And I had also a problem with my variables which are not initialized
because I have forgotten to put before_filter :inivariable at the
beginning of my controller where inivariable is a methode where y define
my variables ex: @articles= Article.find_by_id(1)