What is the best way to be able to add a similar layout to dashing dashboard, like we have in out application. I tried to add the same materalize layout I use throughout my application and it seems to be breaking on each link_to which I have in my main layout.
example of a broken link:
undefined local variable or method `edit_user_registration_path'
adding routes file portion as an example.
Rails.application.routes.draw do
mount Dashing::Engine, at: Dashing.config.engine_path
resources :bills
resources :unit_types, :except => [:show]
end
so if I add link_to bills_path it results in error.
The answer is provided here.
Link
all that is needed is a link_to with main_app before the actual route.
<%= link_to "About", main_app.about_path %>
Related
I'm trying to use a link_to from my view into a nested route and I am sure I just have my syntax incorrect. The basic flow of my app is there is a summary that has many feeds which then have many log lines. its a very basic report
My route is
resources :perfsums, :only => [:index] do
resources :perffeedresults, :only => [:index] do
resources :loglines, :only => [:index] do
end
end
end
Here is how the rake routes looks for that
perfsum_perffeedresult_loglines_path GET /perfsums/:perfsum_id/perffeedresults/:perffeedresult_id/loglines(.:format) loglines#index
In my view I have a link to I want to link from the feed class to log lines using the feed ID. Should be very simple. My link to looks like this
<td> <%= link_to c.id, perfsum_perffeedresult_loglines(c) %> </td>
Going directly to the page by hand works as the link below shows I just can't get there form that link to
http://localhost:3000/perfsums/19/perffeedresults/143/loglines
When I try to run with that link_to I get. I have tried a few different options here none have worked.
undefined method `perfsum_perffeedresult_loglines' for #<#<Class:0x007fad31b60dd8>:0x007fad386d86b0>
I do use a link_to to go from the summary to the feeds page fine its just that extra bit of nesting t hats throwing me off I think.
First of all, it's a perfsum_perffeedresult_loglines_path, you missed _path, which should be added to get a path. And you need to pass two params, look at the path:
/perfsums/:perfsum_id/perffeedresults/:perffeedresult_id/loglines
You need to pass a perfsum and a perffeedresult:
<td> <%= link_to c.id, perfsum_perffeedresult_loglines_path(perfsum, perffeedresult) %> </td>
Ive created a new about page in Ruby on Rails called about.html.erb. How do I create a link to it?
Here is another link I have, Im just not how to write another one for myself.
<%= link_to "Learn more", new_property_path, class: "btn btn-home" %>
check out documentation for #link_to. If you are not sure about second argument you can run bundle exec rake routes and check what url helper you need to use.
You'd probably need to create a route in config/routes.rb for this new "about" action.
An example of route would be:
get "about" => "<name_of_controller>#about", as: "about"
PD: Remember to change the to the actual controller's name.
Then you will be able to use a link like this:
<%= link_to "About", about_path, class: "btn btn-home" %>
<%= link_to "Learn more", new_property_path, class: "btn btn-home" %>
So it's quite straight forward - the first is the name, the last is the css class, you can and probably should reuse these to maintain visual consistency. The middle bit is the piece that will confuse you.
the path comes from your routes.rb file - which is in the config directory. You will need to have a path set up there to use it in the link.
You can run 'rake routes' to see the current mappings that you have. you get a format of:
new_user_account GET /user/new(.:format) user#new
They key to them is that you add path to the first item - so 'new_user_account_path' and it will point to 'user#new' which is the new method in the user controller.
To add routes, you edit the file, and while there are quite a few ways of doing things, your basic CRUD operations are covered by a line of:
resources :users
This will give you more info:
http://guides.rubyonrails.org/routing.html is a guide to this
In my rails project there is a controller and view named "Welcome/index" where index is an action and another one named "home/page" . As i set root"home#page" as my root page. Now i want to transfer from "page.html.erb" into "index.html.erb" . How can i do that. And the code i written is below.Do i have to enter some thing in my controller class. please suggest.
these are the links that i tried. (How to create an anchor and redirect to this specific anchor in Ruby on Rails)
<a rel="nofollow" href="index.html.erb">Transfer to index</a>
You are not supposed to link to .html.erb files, you should link to the methods (not exactly the name of the method, but the name of the route) of a controller.
I strongly encourage you to review the ruby on rails MVC principles. You can read about routing and linking aswell.
Responding to your question, check out the command "rake routes". It will list the defined routes of your app and helps you to use them.
Try to replace your code by this:
<%= link_to 'welcome', welcome_path %>
<%= link_to "Link", controller:"controllername" %>
is the code you should use
You need to make sure a named route is defined for welcome/index and then can use the Rails helper link_to to automatically build your link for you in the view.
In routes.rb:
match '/welcome' => 'welcome#index', :as => :welcome
In your page.html.erb view:
<%= link_to 'Go to Welcome Page', welcome_path %>
If you want go for index action of Welcome controller then you can use:
<%= link_to "Transfer to index", welcome_path %>
Check the rake routes for path.
Plese refer link
I have a page app/views/new/news.html.erb and I simply want to link to this page from within my layouts/application.html.erb. Can someone please help! I have been struggling with this all morning.
I have tried things like <%= link_to "News", ... But I'm not really sure where to go from there.
You don't "link" to a view, you link to a controller which renders that view. Then, you'll need an entry in your routes.rb to wire up the url routing for that controller. If you have a controller named NewsController with a method called index and an entry in your routes.rb that looks like resources :news the following link_to should work: link_to "News", news_path.
In case it's not clear, the index method in your NewsController needs to have render :news in it.
Sounds like you may want to check out the guide on this topic: http://guides.rubyonrails.org/routing.html
If you have it setup correctly you should have a plural for your controller (i.e. news instead of new) and the following should work:
<%= link_to 'News', :controller => "news", :action => :news %>
This is assuming you are using scaffold.
If are adding this folder and page manually: for dynamic page, you have to create an action in your controller. For static page, you have to put it in your public folder.
You can always run
rake routes > routes.txt
in your application directory, which will dump a list of all routes into a txt file. Choose path that leads to action and controller you want, and then supply it as a param for link_to method :)
For some reason the conventional path names for a particular controller are not working? (Rails 3.1)
I created a controller using ryan bates nifty scaffold. Just a controller, no underlying model.
in the controller I have
class ProjectTemplatesController < ApplicationController
# a bunch of stuff
def new
#project = Project.new
end
#more stuff
end
in my view (app/views/project_templates/index.html.erb) I have:
<p><%= link_to "New Project Templates", new_project_templates_path %></p>
however I get the error
undefined local variable or method `new_project_templates_path' for #<#<Class:0x2ab9c24>:0x2ab80e0>
in my routes.rb file I declared the controller as a resource like all the others
resources :project_templates
If I change the link to use
<%= link_to "New Project Templates", {:controller=>"project_templates, :action=>"new"} %>
then it works perfectly?! Why doesnt the naming convension of action_controller_path work in this case?
A simple addendum to the previous posts noting the possibility to run rake routes. If on a POSIX system, run the result through grep or some other text filter.
rake routes | grep project
or
bundle exec rake routes | grep project
Generated routes can get to be very plentiful in large projets so I suggest becoming a command line tools guru in order to efficiently data crunch.
You can find all of the routes and their names on the command line with rake routes.
Rails knows about the pluralization you are using so it could be magically removing it and naming the route new_project_template_path without the 's'?
If you are using resources :project_templates, you could safely to do something like this:
link_to "All Project Templates", :project_templates
link_to "New Project Template", [:new, :project_template]
link_to "Edit Project Template", [:edit, #project_template]
link_to "Show Project Template", #project_template
link_to "Delete Project Template", #project_template, :method => :delete
form_for ProjectTemplate.new do |f|
form_for #projectTemplate do |f|
This way, you don't have to remember the plural or singular problem.
One more thing is that you actually could wrap them all in [] so that you don't worry about them.
link_to "All PT", [:project_templates]
link_to "Show PT", [#project_template]