railscasts

RoR: how can I search only microposts with a specific attribute?

余生长醉 提交于 2019-12-13 22:01:58
问题 Right now in app/views/microposts/home.html.erb I have.. <% form_tag purchases_path, :method => 'get', :id => "products_search" do %> <p> <%= text_field_tag :search, params[:search] %> <%= submit_tag "Search", :name => nil %> </p> <% end %> <% form_tag sales_path, :method => 'get', :id => "sales_search" do %> <p> <%= text_field_tag :search, params[:search] %> <%= submit_tag "Search", :name => nil %> </p> <% end %> and then in micropost.rb I have scope :purchases, where(:kind => "purchase")

rails excel mime-type - how to change default filename?

廉价感情. 提交于 2019-12-13 12:09:57
问题 I followed the http://railscasts.com/episodes/362-exporting-csv-and-excel and set up an Excel Download in my Rails application. My controller code looks like this: def show @project = Project.find(params[:id]) @project.tasks.order(:name) respond_to do |format| format.html format.json { render json: @project } format.xls end end and in my view I create the link to download the excel file like this: .dl_xls= link_to "Download xls", url_for(:format => 'xls') Now the generated excel file is

Ruby on Rails - Railscast #213 Calendar sort by datetime not date

不羁的心 提交于 2019-12-13 07:15:45
问题 I am building an app that involves a calendar. I found that the railscast for building a calendar although dated proved to be very helpful. I have everything up and running I am just trying to allow for the contents on each date to be organized by the datetime and not just the date so they appear in the right chronological order. My current controller looks like this: def index @lessons = Lesson.all @lesson_by_date = @lessons.group_by { |i| i.lesson_date.to_date } @date = params[:date] ? Date

Gettin 500 Internal Server Error in rails on ajax request

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-12 14:13:50
问题 I'm trying to create a record from a form. I've used railscast 136 as ground work. When I trying to submit I get a 500 error for missing partial. I've created the controller correlated javascript view but it is requesting a view with the same name as the model. error message Rendered appointments/create.js.erb (3.8ms) Completed 500 Internal Server Error in 12ms ActionView::Template::Error (Missing partial appointments/appointment with {:locale=>[:en], :formats=>[:js, :html], :handlers=>[:erb,

How to limit nested form fields using jquery not working

喜欢而已 提交于 2019-12-12 05:49:58
问题 i am following Ryan Bates episode on nested form fields and have added the bit of jquery suggested at the end of part 2. Everything works well(i am able to add fields and remove fields). i now want to limit the number of fields you can add in the form. in my application.js i have function add_fields(link, association, content) { var new_id = new Date().getTime(); var regexp = new RegExp("new_" + association, "g") $(link).parent().before(content.replace(regexp, new_id)); } as Ryan Bates has

Rails 3 — Build not saving to database (Railscast 196)

为君一笑 提交于 2019-12-11 23:25:51
问题 I'm following along with railscast 196. I've got two levels of associations. App -> Form -> Question. This is the new action in the form controller. def new @app = App.find(params[:app_id]) @form = Form.new 3.times {@form.questions.build } end the view is displaying all 3 questions fine and I can submit the form... but nothing is inserted into the database for the questions. Here is my create action def create @app = App.find(params[:app_id]) @form = @app.forms.create(params[:form]) respond

rack::offline in rails 4.1 Issue

﹥>﹥吖頭↗ 提交于 2019-12-11 20:31:44
问题 can someone give me a quick solution please? I have done this: My routes: offline = Rack::Offline.configure do cache ActionController::Base.helpers.asset_path("application.css") cache ActionController::Base.helpers.asset_path("application.js") cache ActionController::Base.helpers.asset_path("jquery.min.css") cache ActionController::Base.helpers.asset_path("jquery.tmpl.min.css") cache ActionController::Base.helpers.asset_path("style.js") # cache ActionController::Base.helpers.asset_path(

Routing and checkboxes update from rails 1.x.x to 3.2.8

烂漫一生 提交于 2019-12-11 19:57:24
问题 Just was checking this episode by Ryan Bates (http://railscasts.com/episodes/52-update-through-checkboxes) and it seems that Rails 3.2.x has different setup. Thus map.resources :tasks, :collection => { :complete => :put } does not produce expected result, as it drops an issue that complete_tasks_path does not exist. Could you please let me know how to customise routing in this particular situation? Also seems that check_box_tag requires different attributes other than Ryan puts in there. AS

Railscast authorization from scratch for users

ぃ、小莉子 提交于 2019-12-11 05:38:31
问题 So this is the authorization code I wrote based on Railscast #386. The problem is that the block works on all controllers except for user_controller . In other words, any user can triger edit and update actions on any other user, even though the block given to it is the same as that of favors edit and update actions. def initialize(user) allow :users, [:new, :create, :show] allow :sessions, [:new, :create, :destroy] allow :favors, [:index, :show] if user allow :users, [:edit, :update] do |usr

multiple image uploads in a nested form with carrierwave

微笑、不失礼 提交于 2019-12-11 01:51:18
问题 I'm following railscasts episode 381 in an attempt to allow multiple image uploads to my app with the carrierwave gem & jQuery File upload. My app is for a college project & is set up with a hikingtrails model which has many & accepts nested attributes for a pics model . After I set the multiple option of the file_field to true & hard-coding the input name attribute i.e. <%= form.file_field :image, multiple: true, name: "pic[image]" %> , carrierwave stops working, it doesn't upload a single