I don`t understand this from rails 4:
<td colspan="12" id="compatibility_activities-add" >
<%= job.link_to_add t('shared.add'), :activities,:class => "right small button radius success", :data => { :target => "#activities#{job.object.person_type}_#{job.index}" } %>
</td>
where does the "link_to_add" comes from? there is no references inside the project and cant find anything on the net, there is another "link_to_remove"
this is on a list that creates new rows or deletes them dynamicaly
My second question is, does rails 4 have the way, like laters versions to do rails routes | grep some_route ??
The helper methods you mentioned seem to be provided by the gem Nested Form or some fork of it.
Check your Gemfile for the specific gem name and you can get the official documentation on GitHub or on its website.
In rails 4, you could try using rake routes or bundle exec rake routes to get the list of the routes.
Related
(Saw many posts with these problems and got it working, so I will upload solution)
I'm using Ratyrate without Devise and the stars only appear after a web refresh and they do not save the previously assigned rate.
Fixed this issue with:
Specifying version in each Rating Migration (currently using ActiveRecord::Migration[5.1])
Changing Rate Controller "create" method, replacing "if user_signed_in?" with "if current_user"
Adding "post '/rate' => 'rater#create', :as => 'rate'" to routes.rb (gem should do this for you)
Adding
<%= javascript_include_tag 'ratyrate.js', "data-turbolinks-track": false %> at the bottom of show.html.erb (the view of the model you want to rate)
Hope this helps !
I want to make a view for my website coded in RoR wherein all the available path are listed as links. Is there any way to access the views for various models from the program?
For example, something like:
<%model.views.each do |v| %>
<%= link_to v %>
<% end %>
You could use the sitemap_generator or dynamic_sitemaps gem to generate Sitemaps for your application.
You can use named routes, which allows you to create a link to a different part of your rails app, based on names you set in routes.rb. You can also include route parameters, too, which makes it easy to link to models.
In your routes.rb
get 'test_route/:id' => 'example#controller', as :test
In controllers/views:
link_to #example.name, test_path(id: #example.id)
Further reading on named routes
Im not sure why you want this :), but this will give you the routes
Rails.application.routes.routes
if you want to get all the paths as an array
Rails.application.routes.routes.collect {|r| r.path.spec.to_s }
I am working on my first website using Ruby on Rails. The idea is a nutrition "search engine", where you search for a food and then the web app takes you to either a page with nutrition information about that food or a page of search results if no exact match exists.
So far, I have created the nutrition information database (using Postgresql) and added some test data. This is the command I used to create the scaffolding for the database:
rails generate scaffold Food name:string calories:decimal portion_name:string \
portion:decimal image_url:string description:text
I then created the index page. This is the command I used to create the index:
rails generate controller home index
I removed public/index.html and modified config/routes.rb to contain this line:
root :to => 'home#index'
After this, I added the search form to app/views/home/index.html.erb, like so:
<div id="search">
<h1>How many calories are in... ?</h1>
<%= form_tag("/search", :method => "get") do %>
<%= text_field_tag "q", nil, :class => "span6" %>
<%= submit_tag("Go", :name => nil) %>
<% end %>
</div>
Now, I would like to hook up this search form so that, if there is an exact match to the search query or one near match, the user is routed directly to a page displaying information (from the database) for that food. If there isn't an exact match, I would like the user to be presented with a page of results and links to the nutrition page for each result.
How can I implement this functionality? I have tried googling for articles about implementing search with Rails and I have watched a screencast, also, but none of the resources I have found are implementing quite what I want.
Here's a GitHub link to the project so far: https://github.com/robertseaton/nutrition-project.
I use Thinking-Sphinx for searching in Rails - Sphinx is an open source search server. You can define how you want your search to work right in Rails.
You can also use sunspot to cater to your needs of the search. Here is the github link of sunspot https://github.com/sunspot/sunspot .
Using sunspot you can specify what all items are going to be searchable like food, calories etc. and also give various weights to these items so that if there is a keyword match lets say between food and protien which result should be displayed at the top.
sunspot wiki at github has got lot of resources to get you started and it is very intuitive to implement :).
Thanks,
I recently started working with rails 3. I'm trying to add a multi-modal form into my application. I'm following the steps mentioned at Handle multiple models in one form
When I try to add a link via following helper function, I get
wrong number of arguments (1 for 2)
Code block below.
def add_task_link(name)
link_to_function name do |page|
page.insert_html :bottom, :tasks, :partial => 'task' , :object => Task.new
end
en
Googling for solution didn't take me anywhere.
Thank you.
You should find another tutorial, RJS and prototype are deprecated in rails 3, they've been replaced with jQuery.
If you really insist on going forward, you can bring RJS and prototype back by adding the following to your Gemfile:
gem 'prototype-rails'
This will bring back the correct version of link_to_function.
If you haven't seen my question yesterday, this is my second rails app. The first went nice and smooth, but this one keeps giving me one random error after another. I installed active_scaffold for this app as well as the last app (the first error, instead of using script/install plugin git://active_scaffold repository, I did script/install plugin http://active_scaffold repository.) I didn't want to spell out basic CRUD on minor models. After the install problems, (before I found the http solution from a windows user when I'm on Linux) I thought I'd try out Hobo. Well, Hobo updated actionmailer, actionpack, activerecord, activeresource, and installed rack. Rails isn't even using the updated versions. But as you can see at the bottom of the trace it's using rack. I have a feeling it has something to do with my futzing around with installing Hobo which I uninstalled. Thanks in advance.
[Edit]
I had asked the question over at the
ActiveScaffold Group
the answer (if you don't want to follow the link) was that this line needed to be added to routes:
map.resources :modelName, :active_scaffold => true
It doesn't entirely answer my question, since the documentation said nothing about changing routes. But, it works.
[/Edit]
ActionController::RoutingError in Departments#index
Showing vendor/plugins/active_scaffold/frontends/default/views/_list_header.html.erb where line #8 raised:
No route matches {:_method=>:get, :action=>"show_search", :controller=>"departments"}
Extracted source (around line #8):
5: <% next if controller.respond_to? link.security_method and !controller.send(link.security_method) -%>
6: <% next if link.action == 'new' && params[:nested].nil? && active_scaffold_config.list.always_show_create %>
7: <% next if link.action == 'show_search' && active_scaffold_config.list.always_show_search %>
8: <%= render_action_link(link, new_params) -%>
9: <% end -%>
10:
11: <%= loading_indicator_tag(:action => :table) %>
Trace of template inclusion: vendor/plugins/active_scaffold/frontends/default/views/list.html.erb
Full Trace It was taking forever to format it. I'm still not fully conversant in SO's formatting (sometimes the server is down. reboots are reinstalls. it's a play server)
Add this to routes:
map.resources :modelName, :active_scaffold => true
And, contrary to my edit, it is in the documentation. It's in the wiki at Github. My second question at SO, and I could have found the answer by RTFM'ing. <sigh>
For Rails 4+ at least, your entry in config/routes.rb should look like:
resources :models do # my model name in plural
as_routes
# for action links of type member, add the following
# see also [note, via the action-link API, you can change the HTTP verb. Adjust this route accordingly.
# https://github.com/activescaffold/active_scaffold/wiki/Adding-custom-actions
# get :my_custom_action, :on => :member
end
Note, getting the right version of the Gem requires the following config in your Gemfile:
gem 'active_scaffold', github: 'activescaffold/active_scaffold', :branch => "3-4-stable"
If you get an error that "as_routes" isn't found; that'd be the problem.
THIS IS RAILS 4 ONLY
For Rails 5.x you can set route as follow:
resources :model, concerns: :active_scaffold